• 【PAT甲级】1035 Password


    【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:

    3
    Team000002 Rlsp0dfa
    Team000003 perfectpwd
    Team000001 R1spOdfa
    
    • 1
    • 2
    • 3
    • 4

    Sample Output 1:

    2
    Team000002 RLsp%dfa
    Team000001 R@spodfa
    
    • 1
    • 2
    • 3

    Sample Input 2:

    1
    team110 abcdefg332
    
    • 1
    • 2

    Sample Output 2:

    There is 1 account and no account is modified
    
    • 1

    Sample Input 3:

    2
    team110 abcdefg222
    team220 abcdefg333
    
    • 1
    • 2
    • 3

    Sample Output 3:

    There are 2 accounts and no account is modified
    
    • 1

    思路

    1. 直接对每一个密码串都进行 check 操作,然后将 check 后的密码和原来的密码进行比较,如果不一样就说明已经修改过了,加入答案数组中即可。
    2. check 函数中直接对比每位字符即可,然后分别加入 res 字符串中,最后返回。
    3. 输出的时候要判断是否有密码修改,用 m 来代表修改密码的个数。

    代码

    #include
    using namespace std;
    
    const int N = 1010;
    int n, m;
    string name[N], psd[N];
    
    string check(string x)
    {
        string res;
        //对每个字符进行判断
        for (auto c : x)
            if (c == '1')  res += '@';
            else if (c == '0') res += '%';
            else if (c == 'l') res += 'L';
            else if (c == 'O') res += 'o';
            else res += c;
        return res;
    }
    
    int main()
    {
        cin >> n;
        for (int i = 0; i < n; i++) {
            string a, b;
            cin >> a >> b;
            string c = check(b);	//得到check后的字符串
            //如果和之前不一样则说明被修改过了
            if (c != b)
            {
                name[m] = a;
                psd[m] = c;
                m++;
            }
        }
    
        if (!m) {
            if (n == 1)    puts("There is 1 account and no account is modified");
            else    printf("There are %d accounts and no account is modified\n", n);
        }
        else {
            cout << m << endl;
            for (int i = 0; i < m; i++)
                cout << name[i] << " " << psd[i] << endl;
        }
    
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
  • 相关阅读:
    Redis——》数据类型:bitmap
    数据库mysql实战
    四、Spring Boot 整合 Web开发(1)
    LM-INFINITE: SIMPLE ON-THE-FLY LENGTH GENERALIZATION FOR LARGE LANGUAGE MODELS
    中国财政科学研究院党委书记、院长刘尚希一行莅临麒麟信安调研
    Mbedtls PEM 证书解析失败,错误码-9570: ASN1 tag was of an unexpected value
    antd a-list 添加分页
    1、读Mybatis源码--cache缓存
    Unity中Shader需要了解的点与向量
    定时器的类型
  • 原文地址:https://blog.csdn.net/Newin2020/article/details/126312981