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.
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
题目大意:
对应进行修改,不要求按照用户名字不降输出。
思路:
巧用vector 和 string, 一旦发生修改,则将两个字符串连接在一起输入到vector中。
参考代码:
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int n;
vector<string> ans;
int main(){
string s1, s2, temp;
scanf("%d", &n);
for(int i = 0; i < n; ++i){
cin >> s1 >> s2;
bool flag = true;
for(int j = 0; j < s2.size(); ++j){
if(s2[j] == '1') s2[j] = '@', flag = false;
else if(s2[j] == '0') s2[j] = '%', flag = false;
else if(s2[j] == 'l') s2[j] = 'L', flag = false;
else if(s2[j] == 'O') s2[j] = 'o', flag = false;
}
if(!flag) temp = s1 + " " + s2, ans.push_back(temp);
}
if(!ans.size()){
printf("There %s %d %s and no account is modified", n == 1? "is":"are", n, n == 1?"account": "accounts");
return 0;
}
cout << ans.size() << endl;
for(int i = 0; i < ans.size(); ++i) cout << ans[i]<< endl;
return 0;
}
代码参考:https://blog.youkuaiyun.com/liuchuo/article/details/52121759