拼题 A 系统为提高用户账户的安全性,打算开发一个自动安全预警的功能。对每个账户的每次登录,系统会记录其登录的 IP 地址。每隔一段时间,系统将统计每个账户从多少不同的 IP 地址分别登录了多少次。如果某个账户的登录 IP 超过了 TIP 种,并且登录过于频繁,超过了 Tlogin 次,则会自动向管理员发出警报。
下面就请你实现这个预警功能。
输入格式:
输入首先在第一行中给出三个正整数:N(≤1e4)为登录记录的条数;TIP 和
Tlogin,定义如题面中所描述,均不超过 100。
随后 N 行,每行格式为:e
账户邮箱 IP地址
其中 账户邮箱
为长度不超过 40 的、不包含空格的非空字符串;IP地址
为形如 xxx.xxx.xxx.xxx
的合法 IP 地址。
输出格式:
按照登录所用不同 IP 的数量的非递增顺序,输出每个预警账户的信息。格式为:
账户邮箱
IP1 登录次数
IP2 登录次数
……
其中 IP 按登录次数的非递增顺序输出,如有并列,则按 IP 的递增字典序输出。此外,对所用不同 IP 的数量并列的用户,按其账户邮箱的递增字典序输出。
另一方面,即使没有账户达到预警线,也输出登录所用不同 IP 的数量最多的一批账户的信息。
输入样例 1:
24 3 4
daohaole@qq.com 218.109.231.189
1jiadelaolao@163.com 112.192.203.187
chenyuelaolao@zju.edu.cn 112.18.235.143
jiadelaolao@163.com 112.192.203.187
chenyuelaolao@zju.edu.cn 113.18.235.143
jiadelaolao@163.com 111.192.203.187
daohaole@qq.com 218.109.231.189
chenyuelaolao@zju.edu.cn 111.18.235.143
1jiadelaolao@163.com 115.192.203.187
daohaole@qq.com 113.189.58.141
1jiadelaolao@163.com 111.192.203.187
daohaole@qq.com 112.18.58.145
1jiadelaolao@163.com 114.192.203.187
chenyuelaolao@zju.edu.cn 112.18.235.143
daohaole@qq.com 123.89.158.214
chenyuelaolao@zju.edu.cn 112.18.235.143
youdaohaole@qq.com 218.109.231.189
jiadelaolao@163.com 113.192.203.187
youdaohaole@qq.com 218.109.231.189
jiadelaolao@163.com 114.192.203.187
youdaohaole@qq.com 113.189.58.141
youdaohaole@qq.com 123.89.158.214
1jiadelaolao@163.com 113.192.203.187
youdaohaole@qq.com 112.18.58.145
输出样例 1:
1jiadelaolao@163.com
111.192.203.187 1
112.192.203.187 1
113.192.203.187 1
114.192.203.187 1
115.192.203.187 1
daohaole@qq.com
218.109.231.189 2
112.18.58.145 1
113.189.58.141 1
123.89.158.214 1
youdaohaole@qq.com
218.109.231.189 2
112.18.58.145 1
113.189.58.141 1
123.89.158.214 1
输入样例 2:
24 5 8
daohaole@qq.com 218.109.231.189
1jiadelaolao@163.com 112.192.203.187
chenyuelaolao@zju.edu.cn 112.18.235.143
jiadelaolao@163.com 112.192.203.187
chenyuelaolao@zju.edu.cn 113.18.235.143
jiadelaolao@163.com 111.192.203.187
daohaole@qq.com 218.109.231.189
chenyuelaolao@zju.edu.cn 111.18.235.143
1jiadelaolao@163.com 115.192.203.187
daohaole@qq.com 113.189.58.141
1jiadelaolao@163.com 111.192.203.187
daohaole@qq.com 112.18.58.145
1jiadelaolao@163.com 114.192.203.187
chenyuelaolao@zju.edu.cn 112.18.235.143
daohaole@qq.com 123.89.158.214
chenyuelaolao@zju.edu.cn 112.18.235.143
youdaohaole@qq.com 218.109.231.189
jiadelaolao@163.com 113.192.203.187
youdaohaole@qq.com 218.109.231.189
jiadelaolao@163.com 114.192.203.187
youdaohaole@qq.com 113.189.58.141
youdaohaole@qq.com 123.89.158.214
1jiadelaolao@163.com 113.192.203.187
youdaohaole@qq.com 112.18.58.145
输出样例 2:
1jiadelaolao@163.com
111.192.203.187 1
112.192.203.187 1
113.192.203.187 1
114.192.203.187 1
115.192.203.187 1
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e4+5;
int n,p,q,idx;
map<string,int>mp;
struct node{
int cnt;
string id;
map<string,int>s;
}a[N];
struct ans{
string p;
int k;
};
bool cmp(node a,node b){ return a.s.size()==b.s.size()?a.id<b.id:a.s.size()>b.s.size();}
bool cmp1(ans a,ans b){ return a.k==b.k?a.p<b.p:a.k>b.k;}
int main(){
scanf("%d%d%d",&n,&p,&q);
for(int i=1;i<=n;i++){
string x,y;
cin>>x>>y;
if(mp.count(x)==0){
mp[x]=++idx;
a[mp[x]].id=x;
}
a[mp[x]].cnt++;
a[mp[x]].s[y]++;
}
vector<node>res; //存放答案
for(int i=1;i<=idx;i++){
if(a[i].cnt>q&&a[i].s.size()>p)
res.push_back(a[i]);
}
sort(res.begin(),res.end(),cmp); //账户排序
for(int i=0;i<res.size();i++){
cout<<res[i].id<<endl;
vector<ans>t;
for(auto it:res[i].s) t.push_back({it.first,it.second});
sort(t.begin(),t.end(),cmp1); //IP排序
for(auto it:t) cout<<it.p<<" "<<it.k<<endl;
}
if(res.size()>0) return 0; //存在预警,则直接结束,否则输出最大的一批用户
int maxx=0;
for(int i=1;i<=idx;i++) maxx=max(maxx,int(a[i].s.size()));
for(int i=1;i<=idx;i++){
if(a[i].s.size()==maxx)
res.push_back(a[i]);
}
sort(res.begin(),res.end(),cmp);
for(int i=0;i<res.size();i++){
cout<<res[i].id<<endl;
vector<ans>t;
for(auto it:res[i].s) t.push_back({it.first,it.second});
sort(t.begin(),t.end(),cmp1);
for(auto it:t) cout<<it.p<<" "<<it.k<<endl;
}
return 0;
}