• PAT 1035 Password


    1035 Password

    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:

    There is 1 account and no account is modified
    

    Sample Input 3:

    1. 2
    2. team110 abcdefg222
    3. team220 abcdefg333

    Sample Output 3:

    There are 2 accounts and no account is modified

    总结:这题还是比较简单的,没有太大的难度,但是不知道为什么还有一个测试点没有通过(原来是最后输出的单词打错了!)

    代码:

    1. #include
    2. using namespace std;
    3. int main(){
    4. int n;
    5. cin >> n;
    6. string q[1010];
    7. int cot=0;
    8. for(int i=0;i
    9. string s,t,w;
    10. cin >> s >> t;
    11. w=t;
    12. for(int j=0;jsize();j++){
    13. if(t[j]=='1') t[j]='@';
    14. else if(t[j]=='0') t[j]='%';
    15. else if(t[j]=='l') t[j]='L';
    16. else if(t[j]=='O') t[j]='o';
    17. }
    18. if(w!=t){
    19. q[cot++]=s;
    20. q[cot++]=t;
    21. }
    22. }
    23. if(cot==0 && n==1) printf("There is 1 account and no account is modified\n");
    24. else if(cot==0 && n!=1) printf("There are %d accounts and no accout is modified\n",n);
    25. else{
    26. printf("%d\n",cot/2);
    27. for(int i=0;i
    28. cout << q[i++] << ' ' << q[i++] << endl;
    29. }
    30. }
    31. return 0;
    32. }

     大佬代码:

    最后是将两个字符串和在一起存进了vector数组当中,很好的想法,多学习学习!

    1. #include
    2. #include
    3. using namespace std;
    4. int main() {
    5. int n;
    6. scanf("%d", &n);
    7. vector v;
    8. for(int i = 0; i < n; i++) {
    9. string name, s;
    10. cin >> name >> s;
    11. int len = s.length(), flag = 0;
    12. for(int j = 0; j < len; j++) {
    13. switch(s[j]) {
    14. case '1' : s[j] = '@'; flag = 1; break;
    15. case '0' : s[j] = '%'; flag = 1; break;
    16. case 'l' : s[j] = 'L'; flag = 1; break;
    17. case 'O' : s[j] = 'o'; flag = 1; break;
    18. }
    19. }
    20. if(flag) {
    21. string temp = name + " " + s;
    22. v.push_back(temp);
    23. }
    24. }
    25. int cnt = v.size();
    26. if(cnt != 0) {
    27. printf("%d\n", cnt);
    28. for(int i = 0; i < cnt; i++)
    29. cout << v[i] << endl;
    30. } else if(n == 1) {
    31. printf("There is 1 account and no account is modified");
    32. } else {
    33. printf("There are %d accounts and no account is modified", n);
    34. }
    35. return 0;
    36. }

    好好学习,天天向上!

    我要考研!

    2022.11.3(这个代码还不如之前写的他,唉!)

    1. #include
    2. #include
    3. using namespace std;
    4. typedef pair PII;
    5. int main(){
    6. int n;
    7. scanf("%d",&n);
    8. vector v;
    9. string name,password;
    10. for(int i=0;i
    11. cin >> name >> password;
    12. bool flag=false;
    13. for(char &c:password){
    14. if(c=='1'){
    15. c='@';
    16. flag=true;
    17. }
    18. else if(c=='0'){
    19. c='%';
    20. flag=true;
    21. }
    22. else if(c=='l'){
    23. c='L';
    24. flag=true;
    25. }
    26. else if(c=='O'){
    27. c='o';
    28. flag=true;
    29. }
    30. }
    31. if(flag) v.push_back({name,password});
    32. }
    33. if(v.size()==0){
    34. if(n==1) printf("There is 1 account and no account is modified\n");
    35. else printf("There are %d accounts and no account is modified\n",n);
    36. }
    37. else{
    38. printf("%d\n",v.size());
    39. for(int i=0;isize();i++)
    40. cout << v[i].first << ' ' << v[i].second << endl;
    41. }
    42. return 0;
    43. }

  • 相关阅读:
    Excel表格总是处于只读状态怎么解决?
    进程间通信--信号
    手动从0搭建ABP框架-ABP官方完整解决方案和手动搭建简化解决方案实践
    Linux 内核定时器(高级字符设备五)
    阿里巴巴找黄金宝箱(II)
    Android adb查看系统时间
    跟我学Python图像处理丨基于灰度三维图的图像顶帽运算和黑帽运算
    java--程序流控制
    springboot-iconfont图标如何使用?
    预制菜行业数据分析(京东数据挖掘)
  • 原文地址:https://blog.csdn.net/weixin_50679551/article/details/126922650