目录
题目
题目链接:
1035 Password https://pintia.cn/problem-sets/994805342720868352/problems/994805454989803520
测试样例
输入样例1
3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa
输出样例1
2
Team000002 RLsp%dfa
Team000001 R@spodfa
输入样例2
1
team110 abcdefg332
输出样例2
There is 1 account and no account is modified
输入样例3
There is 1 account and no account is modified
输出样例3
There are 2 accounts and no account is modified
提交结果截图
带详细注释的源代码
#include <cstdio>
#include "string.h"
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct account_info
{
string user_name;
string password;
};
int n;
//1 (one) by @, 0 (zero) by %, l by L, and O by o
//检查是否含有四种字符至少其一,有则修改后返回true,无则直接返回false
bool check_and_change(account_info& ac)
{
int flag = false;
for(int i = 0; i < ac.password.length(); i++)//对密码中每个字符都检查一遍
if (ac.password[i] == '1' || ac.password[i] == '0' || ac.password[i] == 'l' || ac.password[i] == 'O')//检查是否包含四种字符至少其一
{
flag = true;
switch (ac.password[i])//修改字符
{
case '1':ac.password[i] = '@';
break;
case '0':ac.password[i] = '%';
break;
case 'l':ac.password[i] = 'L';
break;
case 'O':ac.password[i] = 'o';
break;
default:
break;
}
}
if (flag)
return true;
else
return false;
}
int main()
{
int num = 0;
vector<account_info>account;
cin >> n;
account_info tmp;
for (int i = 0; i < n; i++)
{
cin >> tmp.user_name >> tmp.password;
//只把需要修改的账号信息存储进向量中,因为不需要修改的账号信息是不需要输出的
if (check_and_change(tmp))
{
account.push_back(tmp);
num++;
}
}
if (!num)//若是一个账号都不需要
{
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;
}
else
{
cout << num << endl;
for (int i = 0; i < account.size(); i++)
cout << account[i].user_name << " " << account[i].password << endl;
}
return 0;
}