修改密码
将输入的用户密码中 1(数字一)替换为 @,将 0(数字零)替换为 %,将 l(L的小写)替换为 L,将O(o的大写)替换为 o。
输入格式
第一行包含一个整数 N,表示用户数量。
接下来 N行,每行包含一个用户名和一个密码,都是长度不超过 10且不含空格的字符串。
输出格式
首先输出一个整数 M,表示已修改的用户密码数量。
接下来M行,每行输出一个用户名称和其修改后的密码。
用户的输出顺序和读入顺序必须相同。
如果没有用户的密码被修改,则输出 There are N accounts and no account is modified,其中 N
是用户总数。
如果 N=1,则应该输出 There is 1 account and no account is modified。
这题主要输出麻烦,并且要熟练使用vector。
C++ 代码
#include<iostream>
#include<cstring>
#include<vector>
#include<utility>
using namespace std;
int main()
{
int n , n1;
cin>>n;
n1 = n;
vector<pair<string,string>> V;
while(n1--)
{
string user_name , user_kep ;
cin>>user_name>>user_kep;
string user_kep2 = "";
bool flag = 0;
for(auto s : user_kep)
{
if(s == '1' or s == '0' or s == 'l' or s == 'O')
{
flag = 1;
if(s == '1')
user_kep2 +="@";
if(s == '0')
user_kep2 +="%";
if( s == 'l')
user_kep2 += "L";
if( s == 'O')
user_kep2 += "o";
}
else user_kep2 += s;
}
if(flag) V.push_back(make_pair(user_name,user_kep2));
}
if(!V.empty())
{
cout<<V.size()<<endl;
for(const auto& pair : V)
{
cout<<pair.first<<" "<<pair.second<<endl;
}
}
else
{
if(n>1) cout<<"There are "<<n<<" accounts and no account is modified"<<endl;//一开始没看到输出的英文句子还要考虑单复数崩溃,错了两次
else cout<<"There is "<<n<<" account and no account is modified"<<endl;
}
}