PAT甲级1035.

目录

A1035

题目

样例

样例1

输入:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

输出:

2
Team000002 RLsp%dfa
Team000001 R@spodfa

样例2

输入:

1
team110 abcdefg332

输出:

There is 1 account and no account is modified

样例3

输入:

2
team110 abcdefg222
team220 abcdefg333

输出:

There are 2 accounts and no account is modified

思路和坑点

  一边读入,一遍把需要修改的密码进行修改,并保存到最终的输出数组中即可,注意特殊情况的输出要求,单复数有别。

AC代码

#include<bits/stdc++.h>
using namespace std;
void check(string &str,int &flag){
    for(int i=0;i<str.size();i++){
        switch(str[i]){
            case '1':str[i]='@';flag=1;break;
            case '0':str[i]='%';flag=1;break;
            case 'l':str[i]='L';flag=1;break;
            case 'O':str[i]='o';flag=1;break;
        }
    }
}
int main(void){
#ifdef ONLINE_JUDGE
#else
    freopen("1.txt","r",stdin);
#endif
    int n,cnt=0;
    vector<string> out;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        string name,passw;
        cin>>name>>passw;
        int flag=0;
        check(passw,flag);
        if(flag==1){
            cnt++;
            out.push_back(name+' '+passw);
        }
    } 
    if(cnt==0){
        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);
    }
    else{
        cout<<cnt<<'\n';
        for(int i=0;i<cnt;i++){
            cout<<out[i]<<'\n';
        }
    }
    return 0;
}