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. Team000003 perfectpwd
  3. 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

之前的题解定义了结构体,较为复杂:

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. using namespace std;
  5. struct Users{
  6. char num[20];
  7. char pass[20];
  8. bool flag = false;
  9. }user[1005];
  10. int main()
  11. {
  12. int N;
  13. int sum=0;
  14. scanf("%d",&N);
  15. int i,j;
  16. for(i=0;i<N;i++)
  17. {
  18. scanf("%s %s",user[i].num,user[i].pass);
  19. for( j=0;j<strlen(user[i].pass);j++)
  20. {
  21. if(user[i].flag!=true)
  22. {
  23. if(user[i].pass[j]=='1') {user[i].pass[j]='@';user[i].flag=true;break;}
  24. if(user[i].pass[j]=='0') {user[i].pass[j]='%';user[i].flag=true;break;}
  25. if(user[i].pass[j]=='l') {user[i].pass[j]='L';user[i].flag=true;break;}
  26. if(user[i].pass[j]=='O') {user[i].pass[j]='o';user[i].flag=true;break;}
  27. }
  28. if(user[i].flag==true)
  29. {
  30. sum++;
  31. break;
  32. }
  33. }
  34. }
  35. if(sum)
  36. {
  37. printf("%d",sum);
  38. for(int i=0;i<N;i++)
  39. {
  40. if(user[i].flag==true)
  41. {
  42. printf("\n");
  43. printf("%s %s",user[i].num,user[i].pass);
  44. }
  45. }
  46. }
  47. else
  48. {
  49. if(N==1)
  50. {
  51. printf("There is 1 account and no account is modified");
  52. }
  53. else
  54. {
  55. printf("There are %d accounts and no account is modified",N);
  56. }
  57. }
  58. }

更好的是:

  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int main() {
  5. int n;
  6. scanf("%d", &n);
  7. vector<string> 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. }
  31. else if(n == 1) {
  32. printf("There is 1 account and no account is modified");
  33. }
  34. else {
  35. printf("There are %d accounts and no account is modified", n);
  36. }
  37. return 0;
  38. }

使用C++里的vectorstring组合将题目解出,省去了使用结构体的麻烦

PAT甲级——1035 Password (20分)的更多相关文章

  1. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

  2. PAT Advanced 1035 Password (20 分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  3. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

  4. PAT 甲级 1035 Password (20 分)

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

  5. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  6. PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)

    1061 Dating (20 分)   Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...

  7. 【PAT甲级】1035 Password (20 分)

    题意: 输入一个正整数N(<=1000),接着输入N行数据,每行包括一个ID和一个密码,长度不超过10的字符串,如果有歧义字符就将其修改.输出修改过多少组密码并按输入顺序输出ID和修改后的密码, ...

  8. PAT (Advanced Level) Practice 1035 Password (20 分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  9. 【PAT】1035. Password (20)

    题目:http://pat.zju.edu.cn/contests/pat-a-practise/1035 分析:简单题.直接搜索,然后替换,不会超时,但是应该有更好的办法. 题目描述: To pre ...

随机推荐

  1. python运算表达式

    运算符1.算术运算符:+,-,*,/,//(求整商),%,**(求多次方,左边为数,右边为多少次方)2.关系运算符:>,<,==,<=,>=,!=3.测试运算:in,not i ...

  2. 005、mysql查询表的结构

    EXPLAIN hcc_ip 如果有一个表,表明为hcc_ip,使用以上语句可以得到下图 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:38247724 ...

  3. 网格视图GridView

    1.常用属性 2.Adapter接口 3.Demo演示 今天观看了GridView的相关视频,并且根据案例,进行了代码的编写和实例 新建GridViewActivity.java继承AppCompat ...

  4. 连接数据库方法2-DBCP

    DBCP(连接池): 解决对数据库建立以及关闭连接时消耗大量资源的解决方案. 程序创建和关闭对数据库连接时会消耗大量的资源,连接池技术帮我们 在程序运行的开始时就预先创建大量的连接,这些连接组成一个池 ...

  5. JS实现时间选择器

    源代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...

  6. Python Learning Day4

    ---恢复内容开始--- 遇到的模块 NumPy:多维数组的有效操作. 高效的数学函数. Matplotlib:可视化:2D和(最近)3D图 SciPy:大型库实现各种数值算法,例如: 线性和非线性方 ...

  7. 无车承运前世今生,5G货运管家期待您的加入

    历时三年的无车承运人试点工作结束,从2020年1月1日起,将执行新的暂行<办法>,在这样一个承前启后的阶段,无车承运人的命运如何?网络货运经营者又是何物? 在新赛道下,将迎来什么样的机遇和 ...

  8. 把Android studio的日志导入目标文件中

    最好是在Android studio的命令行工具中进行命令操作. adb logcat -v time > /Users/z/log.txt adb logcat -v time > /U ...

  9. UML-迭代3-中级主题

    初始阶段和迭代1:揭示了大量面向对象分析和设计建模的基础知识. 迭代2:特别强调对象设计模式 迭代3:涉及主题比较宽泛: 1).更多GoF设计模式及其在框架(尤其是一个持久化框架)的设计中的应用. 2 ...

  10. 2019~2020icpc亚洲区域赛徐州站H. Yuuki and a problem

    2019~2020icpc亚洲区域赛徐州站H. Yuuki and a problem 题意: 给定一个长度为\(n\)的序列,有两种操作: 1:单点修改. 2:查询区间\([L,R]\)范围内所有子 ...