天天看點

PAT 甲級 1035  Password

1035 Password (20 point(s))

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:

Sample Input 1:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa      

Sample Output 1:

2
Team000002 RLsp%dfa
Team000001 R@spodfa      

Sample Input 2:

1
team110 abcdefg332      

Sample Output 2:

There is 1 account and no account is modified      

Sample Input 3:

2
team110 abcdefg222
team220 abcdefg333      

Sample Output 3:

There are 2 accounts and no account is modified      

經驗總結:

AC代碼 

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
using namespace std;
struct node
{
    char a[20],b[20];
}s;
bool judge(node & x)
{
    int flag=0;
    int len=strlen(x.b);
    for(int i=0;i<len;++i)
    {
        if(x.b[i]=='1')
        {
            x.b[i]='@';
            flag=1;
        }
        else if(x.b[i]=='l')
        {
            x.b[i]='L';
            flag=1;
        }
        else if(x.b[i]=='0')
        {
            x.b[i]='%';
            flag=1;
        }
        else if(x.b[i]=='O')
        {
            x.b[i]='o';
            flag=1;
        }
    }
    return flag;
}
int main()
{
    int n;
    scanf("%d",&n);
    string a,b;
    vector<node> ans;
    for(int i=0;i<n;++i)
    {
        scanf("%s %s",s.a,s.b);
        if(judge(s))
        {
            ans.push_back(s);
        }
    }
    if(ans.size()==0)
    {
        if(n==1)
            printf("There is 1 account and no account is modified\n");
        else
            printf("There are %d accounts and no account is modified\n",n);
    }
    else
    {
        printf("%d\n",ans.size());
        for(int i=0;i<ans.size();++i)
        {
            printf("%s %s\n",ans[i].a,ans[i].b);
        }
    }
    return 0;
}