原题
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), 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
大体翻译
有小于等于1000个的用户名和密码,对每个密码检查1
0
l
O
这四个字符,如果是数字1
要将其转换为@
,如果是数字0
要将其转换为%
,如果是小写的l
要将其转换为大写的L
,如果是大写的O
要将其转换为小写的o
如果N个密码里没有需要转换的,则输出There are N accounts and no account is modified
,其中N为输入的用户总数,如果N为1的话,还有is
和are
的区分
如果N个密码里有需要转换的,则输出需要转换的密码的个数,和所有转换后的用户名、密码
整体思路
用结构体来存储数据,里面的数据有用户名和密码
然后遍历结构体,在每一个结构体里遍历密码,如果密码为上述4个字符则将其转换为对应的字符,并且设置一个标志,如果有转换则标志为1,如果没有则保持0。遍历完密码以后检查标志,如果标志为1,则表示该用户有过转换,将用户对应的位置保存如一个数字数组,计数m加1
遍历结束以后,检查m:
如果m为0,则表示所有用户都没有转换,此时检查N为1还是非1,输出对应的字符串
如果m不为0,则遍历记录位置的数字数组,输出数字数组在结构体对应位置的数据
第一次编写
#include <iostream>
using namespace std;
typedef struct user
{
string name;
string password;
}user;
void count(user a[], int n)
{
int b[1000];
int m = 0;
for (int i = 0; i < n; i++)
{
int flag = 0;
for (int j = 0; j < a[i].password.length(); j++)
{
//cout << a[i].password[j];
if (a[i].password[j] == '0')
{
a[i].password[j] = '%';
flag = 1;
}
else if (a[i].password[j] == '1')
{
a[i].password[j] = '@';
flag = 1;
}
else if (a[i].password[j] == 'l')
{
a[i].password[j] = 'L';
flag = 1;
}
else if (a[i].password[j] == 'O')
{
a[i].password[j] = 'o';
flag = 1;
}
}
if (flag == 1)
{
b[m] = i;
m++;
}
}
if (m == 0)
{
if (n == 1)
{
cout << "There is 1 account and no account is modified" << endl;
}
else
{
cout << "There are " << n << " accounts and no account is modified" << endl;
}
}
else
{
cout << m << endl;
for (int i = 0; i < m; i++)
{
int j = b[i];
cout << a[j].name << " " << a[j].password << endl;
}
}
}
int main()
{
user a[1000];
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i].name >> a[i].password;
}
count(a, n);
return 0;
}