很常规的字符串处理
其实这道题用find(str)和replace(it1,it2,str2)也可以,但是仔细想想其实还不如自己循环然后手动if方便呢
代码如下
#include <iostream>
#include <string>
using namespace std;
const int MaxN=1000+5;
struct account{
string name,password;
bool modify=false;//默认没有被修改
};
int main()
{
account student[MaxN];
int N,count=0;//count是被修改的数量
cin>>N;
for(int i=0;i<N;i++){
cin>>student[i].name>>student[i].password;
for(int j=0;j<student[i].password.size();j++){
if(student[i].password[j]=='1'){
student[i].password[j]='@';
student[i].modify=true;
}
else if(student[i].password[j]=='0'){
student[i].password[j]='%';
student[i].modify=true;
}
else if(student[i].password[j]=='l'){
student[i].password[j]='L';
student[i].modify=true;
}
else if(student[i].password[j]=='O'){
student[i].password[j]='o';
student[i].modify=true;
}
}
if(student[i].modify==true)//被修改了count++
count++;
}
if(count==0&&N==1)
cout<<"There is 1 account and no account is modified"<<endl;
else if(count==0)
cout<<"There are "<<N<<" accounts and no account is modified"<<endl;
else{
cout<<count<<endl;
for(int i=0;i<N;i++){
if(student[i].modify==true)
cout<<student[i].name<<" "<<student[i].password<<endl;
}
}
return 0;
}