• 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. }

  • 相关阅读:
    11 编译2022年最新的Linux kernel 6.1源码,并用QEMU模拟器运行
    Redis集群高可用环境之哨兵机制(12)
    【C++】C++11—— 包装器
    基于斑马优化的BP神经网络(分类应用) - 附代码
    2022/8/10 考试总结
    微服务14:微服务治理之重试
    继电器的选型和英应用
    【图像去雾】基于颜色衰减先验的图像去雾附matlab代码
    保姆级使用PyTorch训练与评估自己的Swin Transformer V2网络教程
    一次不完整的渗透
  • 原文地址:https://blog.csdn.net/weixin_68051436/article/details/125882543