PAT Class A -------------1035. Password (20)

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.


Note: 1. When there is only one team, that is, when n==1, the output There is 1 account and no account is modified

2. Note that when n>1, the complex form should be output

The code is below, it's poorly written


#include <bits/stdc++.h>

using namespace std;

char IsHave(char &ch) ///Used to determine whether there is a function in the string that meets the requirements
{
    if(ch == '1')
    {
        ch = '@';
        return ch;
    }
    if(ch == 'l')
    {
        ch = 'L';
        return ch;
    }
    if(ch == '0')
    {
        ch = '%';
        return ch;
    }
    if(ch == 'O')
    {
        ch = 'o';
        return ch;
    }
    return ch;
}
string str[1200][2];
int M[1200] ={0};
intmain()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>str[i][0];             ///Team Name
        cin>>str[i][1];         ///Password
    }
    int cnt = 0;
    for(int i=0; i<n; i++)
    {
        string ss = str[i][1];
        int len = ss.length();
        bool flag = false;
        for(int j=0; j<len; j++)
        {
            char ch = ss[j];
            if( ch != IsHave(ss[j]))            ///If have
                flag = true;
        }
        if(flag == true)
        {
            M[i] = 1;
            str[i][1] = ss;
            cnt++;
        }
    }
    if( n == 1)
    {
        cout<<"There is "<<n<<" account and no account is modified";
    }
    else if(cnt == 0)
    {
        cout<<"There are "<<n<<" accounts and no account is modified";
    }
    if(cnt !=0 && n != 1)
    {
        cout<<cnt<<endl;
        for(int i=0; i<n; i++)
        {
            if(M[i]==1)
                cout<<str[i][0]<<" "<<str[i][1]<<endl;
        }
    }
    return 0;
}






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324644950&siteId=291194637