• PAT甲级--1035 Password


    题目详情 - 1035 Password (pintia.cn)

    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:

    当没有需要修改的时:

    N = 1时输出

    There is 1 account and no account is modified
    

    N > 1时输出:

    There is N account and no account is modified
    

    代码:

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

  • 相关阅读:
    linux用户组管理
    C语言--typedef的使用
    在 Python 中构建高度可扩展的数据流管道
    论文阅读——InternImage(cvpr2023)
    复制一个项目后,错误: 找不到或无法加载主类 原因: java.lang.ClassNotFoundException:
    过滤器模式 rust和java的实现
    API 版本控制【 Eolink 翻译】
    9.0 堆体系结构概述之GC
    Codeforces Round #822 (Div. 2) C. Removing Smallest Multiples
    Linux MMC子系统 - 1.eMMC简介
  • 原文地址:https://blog.csdn.net/weixin_68051436/article/details/125882543