AcWing 刷题记录 1519.密码
思路
每输入一组数据,进行更改密码字符串,之后比较原密码与修改之后的密码是否相等,不相等记录加一。
代码
#include<iostream>
using namespace std;
const int N = 1010;
string changed_name[N],changed_pwd[N];
// 修改字符串函数
string change(string pwd)
{
string res;
for(auto c:pwd)
{
if(c == '1')
{
res = res + '@';
}
else if(c == '0')
{
res = res + '%';
}
else if(c == 'l')
{
res = res + 'L';
}
else if(c == 'O')
{
res = res + 'o';
}
else
{
res = res + c;
}
}
return res;
}
int main()
{
int m;
cin>>m;
string cur_name,cur_pwd;
int count = 0;
for(int i = 0; i < m; i++)
{
cin>>cur_name>>cur_pwd;
string changePwd = change(cur_pwd);
if(changePwd != cur_pwd)
{
// 记录修改的id以及字符串
changed_name[count] = cur_name;
changed_pwd[count] = changePwd;
count++;
}
}
if(count == 0)
{
if(m == 1)
{
cout<<"There is 1 account and no account is modified"<<endl;
}
else
{
printf("There are %d accounts and no account is modified",m);
}
}
else
{
cout<<count<<endl;
for(int i = 0; i < count; i++)
{
cout<<changed_name[i]<<' '<<changed_pwd[i]<<endl;
}
}
return 0;
}