题意分析:
(1)给出若干个PAT考试登陆账户,为了防止账户密码中有个别引起混淆的字母和数字(l,1,O,0),统计密码中出现可能混淆的字母的账户个数,并将修改后的账户按原来的顺序输出
可能坑点:
(1)注意:当没有出现混淆字母的账户时候,如果原来有N条记录,则要区分N=1和N!=1时候,输出结果的account和accounts单复数之别
(2)注意,在G++的编译器当中,当使用cout输出流的时候,cout<<"There are “<<N<<”...“<<endl;是错误的,一旦使用了这样的输出方式,会导致第二个测试案例过不去
#include <iostream>
#include <string.h>
#include <vector>
#include <stdio.h>
using namespace std;
struct userInfo
{
string userName,passWord;
};
vector<userInfo>accounts;
bool check(string &passWord)
{
bool isModified=0;
for(int i=0;i<=passWord.length();i++)
{
if(passWord[i]=='1')
{
isModified=1;
passWord[i]='@';
}
else if(passWord[i]=='0')
{
isModified=1;
passWord[i]='%';
}
else if(passWord[i]=='l')
{
isModified=1;
passWord[i]='L';
}
else if(passWord[i]=='O')
{
isModified=1;
passWord[i]='o';
}
}
return isModified;
}
int main()
{
int N,i=0,cnt=0;
scanf("%d",&N);
string userName,passWord;
userInfo temp;
while(i<N)
{
cin>>userName>>passWord;
if(check(passWord))
{
cnt++;
temp.userName=userName;
temp.passWord=passWord;
accounts.push_back(temp);
}
i++;
}
if(cnt==0)
{
if(N==1) printf("There is 1 account and no account is modified\n");
else printf("There are %d accounts and no account is modified\n",N);
}
else
{
cout<<cnt<<endl;
vector<userInfo>::iterator it=accounts.begin();
for(;it!=accounts.end();it++)cout<<(*it).userName<<" "<<(*it).passWord<<endl;
}
return 0;
}