题目:
为了PAT做准备,法官有时必须为用户生成随机密码。问题是总是存在一些令人混淆的密码,因为很难区分1
(一)和l
(小写L
),或0
(零)和O
(大写o
)。一种解决方案是将1
(一)替换为@
,0
(零)替换为%
,l
替换为L
,O
替换为o
。现在,你的工作是编写一个程序来检查由法官生成的帐户,并帮助该法官修改令人困惑的密码。
输入格式:
每个输入文件都包含一个测试用例。每个情况下包含一个正整数N(≤1000),后面是N行帐户。每个帐户由一个用户名和一个密码组成,它们都是不超过10个字符的字符串,没有空格。
输出格式:
对于每个测试用例,首先打印已修改的帐户数M,然后在以下M行打印修改后的帐户信息,即用户名和相应的修改密码。帐户的打印顺序必须与读取帐户的打印顺序相同。如果没有修改任何帐户,则按一行There are N accounts and no account is modified
,并且没有修改任何帐户,其中N
为帐户总数。但是,如果N
为1,则必须打印There is 1 account and no account is modified
。
输入样例1:
3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa
输出样例1:
2
Team000002 RLsp%dfa
Team000001 R@spodfa
输入样例2:
1
team110 abcdefg332
输出样例2:
There is 1 account and no account is modified
输入样例3:
2
team110 abcdefg222
team220 abcdefg333
输出样例3:
There are 2 accounts and no account is modified
AC代码:
#include<iostream>
using namespace std;
const int maxn=1010;
struct user{
char name[15];
char password[15];
int tag=0;
}us[maxn];
int main(){
int n;
cin>>n;
int i,modified=0,j;
for(i=0;i<n;i++){
cin>>us[i].name>>us[i].password;
for(j=0;us[i].password[j]!='\0';j++){
if(us[i].password[j]=='1'){
us[i].password[j]='@';
us[i].tag=1;
}
if(us[i].password[j]=='0'){
us[i].password[j]='%';
us[i].tag=1;
}
if(us[i].password[j]=='l'){
us[i].password[j]='L';
us[i].tag=1;
}
if(us[i].password[j]=='O'){
us[i].password[j]='o';
us[i].tag=1;
}
}
if(us[i].tag==1)
modified++;
}
if(modified==0){
if(n>1)
cout<<"There are "<<n<<" accounts and no account is modified";
else
cout<<"There is "<<n<<" account and no account is modified";
}
else{
cout<<modified<<endl;
for(i=0;i<n;i++){
if(us[i].tag==1){
cout<<us[i].name<<" "<<us[i].password<<endl;
}
}
}
return 0;
}