\quad
字符串处理题,分别判断密码有没有需要修改的字符,按要求修改后统计修改的数量,然后就是按照要求输出即可。
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
string change(string s)
{
string res = "";
for (int i = 0; i < s.length(); ++i)
{
if(s[i]=='1') res += '@';
else if(s[i]=='0') res += '%';
else if(s[i]=='l') res += 'L';
else if(s[i]=='O') res += 'o';
else res += s[i];
}
return res;
}
int main(int argc, char const *argv[])
{
int N, M;
cin >> N;
vector<pair<string, string> > res;
for (int i = 0; i < N; ++i)
{
string name, password;
cin >> name >> password;
string s = change(password);
if(s==password) continue; // 没有修改
res.push_back(make_pair(name, s));
}
M = res.size();
if(M==0) // 没有被修改的情况
{
if(N==1) cout << "There is 1 account and no account is modified" << endl;
else cout << "There are " << N << " accounts and no account is modified" << endl;
return 0;
}
cout << M << endl;
for (int i = 0; i < M; ++i)
{
cout << res[i].first << " " << res[i].second << endl;
}
return 0;
}