PAT 甲级 1035 Password (20 分)

布满荆棘的人生 2024-02-19 21:02 136阅读 0赞

1035 Password (20 分)

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N (≤1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.

Output Specification:

For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line There are N accounts and no account is modified where N is the total number of accounts. However, if N is one, you must print There is 1 account and no account is modified instead.

Sample Input 1:

  1. 3
  2. Team000002 Rlsp0dfa
  3. Team000003 perfectpwd
  4. Team000001 R1spOdfa

Sample Output 1:

  1. 2
  2. Team000002 RLsp%dfa
  3. Team000001 R@spodfa

Sample Input 2:

  1. 1
  2. team110 abcdefg332

Sample Output 2:

  1. There is 1 account and no account is modified

Sample Input 3:

  1. 2
  2. team110 abcdefg222
  3. team220 abcdefg333

Sample Output 3:

  1. There are 2 accounts and no account is modified

有个坑点:

2019071822284377.png

考察细心程度,看单复数。

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. using namespace std;
  5. struct node{
  6. string a,b;
  7. };
  8. int main()
  9. {
  10. node s[1000];
  11. int f=0,i,j,m,k=0;
  12. string t1,t2;
  13. cin>>m;
  14. for(j=0;j<m;j++)
  15. {
  16. int t_f=0;
  17. cin>>t1>>t2;
  18. for(i=0;i<t2.length();i++)
  19. {
  20. if(t2[i]=='1')
  21. {
  22. t_f=1;
  23. t2[i]='@';
  24. }
  25. else
  26. if(t2[i]=='0')
  27. {
  28. t_f=1;
  29. t2[i]='%';
  30. }
  31. else
  32. if(t2[i]=='l')
  33. {
  34. t_f=1;
  35. t2[i]='L';
  36. }
  37. else
  38. if(t2[i]=='O')
  39. {
  40. t_f=1;
  41. t2[i]='o';
  42. }
  43. }
  44. if(t_f==1)
  45. {
  46. s[k].a=t1;
  47. s[k++].b=t2;
  48. }
  49. }
  50. if(k!=0)
  51. {
  52. cout<<k<<endl;
  53. for(i=0;i<k;i++)
  54. cout<<s[i].a<<" "<<s[i].b<<endl;
  55. }
  56. else
  57. {
  58. if(k!=1)
  59. cout<<"There are "<<m<<" accounts and no account is modified"<<endl;
  60. else
  61. cout<<"There is 1 account and no account is modified"<<endl;
  62. }
  63. return 0;
  64. }

发表评论

表情:
评论列表 (有 0 条评论,136人围观)

还没有评论,来说两句吧...

相关阅读