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

  • 相关阅读:
    C++入门第八篇---STL模板---list的模拟实现
    IceRPC之服务器地址与TLS的安全性->快乐的RPC
    Java自动装箱与拆箱及其陷阱
    【算法-数组1】二分查找 和 移除元素
    LC买卖股票的最佳时机Ⅱ(三种解法详解)
    卷积神经网络卷积计算,卷积网络计算公式
    【手把手】教你玩转SpringCloud Alibaba之Seata
    人到中年,是安逸的活着还是再拼一把?
    zabbix部署,安装zabbix-agent监控linux和windows
    【前端面试知识题】- 2. 浏览器
  • 原文地址:https://blog.csdn.net/weixin_68051436/article/details/125882543