原题:1035. Password (20)
解题思路:
按题意进行即可,注意一个陷阱:样例在没有修改时n = 1与n > 1输出不同即可。
代码如下:
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 1000 + 5;
struct student
{
char id[15];
char password[15];
int check;
} stu[maxn];
bool check(char& a)
{
if(a == '1') {a = '@'; return true;}
if(a == 'l') {a = 'L'; return true;}
if(a == '0') {a = '%'; return true;}
if(a == 'O') {a = 'o'; return true;}
return false;
}
bool trans(char s[], int len)
{
bool flag = false;
for(int i = 0; i < len; i++)
if(check(s[i])) flag = true;
return flag;
}
int main()
{
int n;
while(scanf("%d", &n) == 1)
{
for(int i = 0; i < n; i++)
{
scanf("%s%s", stu[i].id, stu[i].password);
stu[i].check = 0;
}
int cnt = 0;
for(int i = 0; i < n; i++)
{
int len = strlen(stu[i].password);
if(trans(stu[i].password, len)){cnt++; stu[i].check = 1;}
}
int i = 0;
if(cnt == 0 && n > 1) printf("There are %d accounts and no account is modified\n", n);
else if (cnt == 0) printf("There is %d account and no account is modified\n", n);
else
{
printf("%d\n", cnt);
while(cnt)
{
if(stu[i].check) { printf("%s %s\n", stu[i].id, stu[i].password); cnt--;}
i++;
}
}
}
return 0;
}