题目详情 - 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) froml
(L
in lowercase), or0
(zero) fromO
(o
in uppercase). One solution is to replace1
(one) by@
,0
(zero) by%
,l
byL
, andO
byo
. 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
whereN
is the total number of accounts. However, ifN
is one, you must printThere 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
check
操作,然后将 check
后的密码和原来的密码进行比较,如果不一样就说明已经修改过了,加入答案数组中即可。check
函数中直接对比每位字符即可,然后分别加入 res
字符串中,最后返回。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;
}