题目大意:判断给出的字符串中是否有指定的字符,如果有,替换掉这些字符并输出。
直接替换就好。
AC代码:
#include <iostream>
#include <vector>
#include <map>
using namespace std;
bool modified(string &str, map<char, char>&mp)
{
bool ret = false;
for (int i = 0; i < str.size(); ++i)
{
if(str[i] == '1' || str[i] == '0' || str[i] == 'l' || str[i] == 'O')
{
str[i] = mp[str[i]];
ret = true;
}
}
return ret;
}
struct user
{
string id;
string password;
user(string id, string password):id(id), password(password){};
};
int main()
{
map<char, char>mp;
mp['1'] = '@';
mp['0'] = '%';
mp['l'] = 'L';
mp['O'] = 'o';
int N;
cin >> N;
vector<user> v;
for (int i = 0; i < N; ++i)
{
string id, password;
cin >> id >> password;
if(modified(password,mp)) v.push_back(user(id, password));
}
if(v.size() > 0)
{
cout << v.size() << endl;
for (int i = 0; i < v.size(); ++i)
{
cout << v[i].id << " " << v[i].password << endl;
}
}
else
{
if(N == 1) cout << "There is 1 account and no account is modified";
else cout << "There are " << N << " accounts and no account is modified";
}
return 0;
}