当前位置:   article > 正文

2021Robocom决赛---账户安全预警_拼题 a 系统为提高用户账户的安全性,打算开发一个自动安全预警的功能。对每个账户

拼题 a 系统为提高用户账户的安全性,打算开发一个自动安全预警的功能。对每个账户

拼题 A 系统为提高用户账户的安全性,打算开发一个自动安全预警的功能。对每个账户的每次登录,系统会记录其登录的 IP 地址。每隔一段时间,系统将统计每个账户从多少不同的 IP 地址分别登录了多少次。如果某个账户的登录 IP 超过了 TIP​ 种,并且登录过于频繁,超过了 Tlogin​ 次,则会自动向管理员发出警报。

下面就请你实现这个预警功能。

输入格式:

输入首先在第一行中给出三个正整数:N(≤1e4)为登录记录的条数;TIP​ 和
Tlogin​,定义如题面中所描述,均不超过 100。

随后 N 行,每行格式为:e

账户邮箱 IP地址

其中 账户邮箱 为长度不超过 40 的、不包含空格的非空字符串;IP地址 为形如 xxx.xxx.xxx.xxx 的合法 IP 地址。

输出格式:

按照登录所用不同 IP 的数量的非递增顺序,输出每个预警账户的信息。格式为:

  1. 账户邮箱
  2. IP1 登录次数
  3. IP2 登录次数
  4. ……

其中 IP 按登录次数的非递增顺序输出,如有并列,则按 IP 的递增字典序输出。此外,对所用不同 IP 的数量并列的用户,按其账户邮箱的递增字典序输出。

另一方面,即使没有账户达到预警线,也输出登录所用不同 IP 的数量最多的一批账户的信息。

输入样例 1:

  1. 24 3 4
  2. daohaole@qq.com 218.109.231.189
  3. 1jiadelaolao@163.com 112.192.203.187
  4. chenyuelaolao@zju.edu.cn 112.18.235.143
  5. jiadelaolao@163.com 112.192.203.187
  6. chenyuelaolao@zju.edu.cn 113.18.235.143
  7. jiadelaolao@163.com 111.192.203.187
  8. daohaole@qq.com 218.109.231.189
  9. chenyuelaolao@zju.edu.cn 111.18.235.143
  10. 1jiadelaolao@163.com 115.192.203.187
  11. daohaole@qq.com 113.189.58.141
  12. 1jiadelaolao@163.com 111.192.203.187
  13. daohaole@qq.com 112.18.58.145
  14. 1jiadelaolao@163.com 114.192.203.187
  15. chenyuelaolao@zju.edu.cn 112.18.235.143
  16. daohaole@qq.com 123.89.158.214
  17. chenyuelaolao@zju.edu.cn 112.18.235.143
  18. youdaohaole@qq.com 218.109.231.189
  19. jiadelaolao@163.com 113.192.203.187
  20. youdaohaole@qq.com 218.109.231.189
  21. jiadelaolao@163.com 114.192.203.187
  22. youdaohaole@qq.com 113.189.58.141
  23. youdaohaole@qq.com 123.89.158.214
  24. 1jiadelaolao@163.com 113.192.203.187
  25. youdaohaole@qq.com 112.18.58.145

输出样例 1:

  1. 1jiadelaolao@163.com
  2. 111.192.203.187 1
  3. 112.192.203.187 1
  4. 113.192.203.187 1
  5. 114.192.203.187 1
  6. 115.192.203.187 1
  7. daohaole@qq.com
  8. 218.109.231.189 2
  9. 112.18.58.145 1
  10. 113.189.58.141 1
  11. 123.89.158.214 1
  12. youdaohaole@qq.com
  13. 218.109.231.189 2
  14. 112.18.58.145 1
  15. 113.189.58.141 1
  16. 123.89.158.214 1

输入样例 2:

  1. 24 5 8
  2. daohaole@qq.com 218.109.231.189
  3. 1jiadelaolao@163.com 112.192.203.187
  4. chenyuelaolao@zju.edu.cn 112.18.235.143
  5. jiadelaolao@163.com 112.192.203.187
  6. chenyuelaolao@zju.edu.cn 113.18.235.143
  7. jiadelaolao@163.com 111.192.203.187
  8. daohaole@qq.com 218.109.231.189
  9. chenyuelaolao@zju.edu.cn 111.18.235.143
  10. 1jiadelaolao@163.com 115.192.203.187
  11. daohaole@qq.com 113.189.58.141
  12. 1jiadelaolao@163.com 111.192.203.187
  13. daohaole@qq.com 112.18.58.145
  14. 1jiadelaolao@163.com 114.192.203.187
  15. chenyuelaolao@zju.edu.cn 112.18.235.143
  16. daohaole@qq.com 123.89.158.214
  17. chenyuelaolao@zju.edu.cn 112.18.235.143
  18. youdaohaole@qq.com 218.109.231.189
  19. jiadelaolao@163.com 113.192.203.187
  20. youdaohaole@qq.com 218.109.231.189
  21. jiadelaolao@163.com 114.192.203.187
  22. youdaohaole@qq.com 113.189.58.141
  23. youdaohaole@qq.com 123.89.158.214
  24. 1jiadelaolao@163.com 113.192.203.187
  25. youdaohaole@qq.com 112.18.58.145

输出样例 2:

  1. 1jiadelaolao@163.com
  2. 111.192.203.187 1
  3. 112.192.203.187 1
  4. 113.192.203.187 1
  5. 114.192.203.187 1
  6. 115.192.203.187 1
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int N=1e4+5;
  5. int n,p,q,idx;
  6. map<string,int>mp;
  7. struct node{
  8. int cnt;
  9. string id;
  10. map<string,int>s;
  11. }a[N];
  12. struct ans{
  13. string p;
  14. int k;
  15. };
  16. bool cmp(node a,node b){ return a.s.size()==b.s.size()?a.id<b.id:a.s.size()>b.s.size();}
  17. bool cmp1(ans a,ans b){ return a.k==b.k?a.p<b.p:a.k>b.k;}
  18. int main(){
  19. scanf("%d%d%d",&n,&p,&q);
  20. for(int i=1;i<=n;i++){
  21. string x,y;
  22. cin>>x>>y;
  23. if(mp.count(x)==0){
  24. mp[x]=++idx;
  25. a[mp[x]].id=x;
  26. }
  27. a[mp[x]].cnt++;
  28. a[mp[x]].s[y]++;
  29. }
  30. vector<node>res; //存放答案
  31. for(int i=1;i<=idx;i++){
  32. if(a[i].cnt>q&&a[i].s.size()>p)
  33. res.push_back(a[i]);
  34. }
  35. sort(res.begin(),res.end(),cmp); //账户排序
  36. for(int i=0;i<res.size();i++){
  37. cout<<res[i].id<<endl;
  38. vector<ans>t;
  39. for(auto it:res[i].s) t.push_back({it.first,it.second});
  40. sort(t.begin(),t.end(),cmp1); //IP排序
  41. for(auto it:t) cout<<it.p<<" "<<it.k<<endl;
  42. }
  43. if(res.size()>0) return 0; //存在预警,则直接结束,否则输出最大的一批用户
  44. int maxx=0;
  45. for(int i=1;i<=idx;i++) maxx=max(maxx,int(a[i].s.size()));
  46. for(int i=1;i<=idx;i++){
  47. if(a[i].s.size()==maxx)
  48. res.push_back(a[i]);
  49. }
  50. sort(res.begin(),res.end(),cmp);
  51. for(int i=0;i<res.size();i++){
  52. cout<<res[i].id<<endl;
  53. vector<ans>t;
  54. for(auto it:res[i].s) t.push_back({it.first,it.second});
  55. sort(t.begin(),t.end(),cmp1);
  56. for(auto it:t) cout<<it.p<<" "<<it.k<<endl;
  57. }
  58. return 0;
  59. }

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号