PAT甲级 1035. Password (20)

来源:互联网 发布:企业内部数据共享方案 编辑:程序博客网 时间:2024/06/09 14:36

题目:

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N (<= 1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.

Output Specification:

For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line "There are N accounts and no account is modified" where N is the total number of accounts. However, if N is one, you must print "There is 1 account and no account is modified" instead.

Sample Input 1:

3Team000002 Rlsp0dfaTeam000003 perfectpwdTeam000001 R1spOdfa
Sample Output 1:
2Team000002 RLsp%dfaTeam000001 R@spodfa
Sample Input 2:
1team110 abcdefg332
Sample Output 2:
There is 1 account and no account is modified
Sample Input 3:
2team110 abcdefg222team220 abcdefg333
Sample Output 3:
There are 2 accounts and no account is modified
思路:

这道题很简单,只是简单地将字符串中特定的字符进行替换

代码:

#include<iostream>#include<string>#include<vector>using namespace std;struct user{string name;string password;};int main(){
//输入int N;cin >> N;vector<user> users(N);int i = 0;for (; i < N; ++i){cin >> users[i].name >> users[i].password;}//替换int j;vector<user> modified;bool flag = 0;for (i = 0; i < N; ++i){flag = 0;for (j = 0; j < users[i].password.size(); ++j){switch (users[i].password[j]){case '1':{flag = 1;users[i].password[j] = '@';break;}case '0':{flag = 1;users[i].password[j] = '%';break;}case 'l':{flag = 1;users[i].password[j] = 'L';break;}case 'O':{flag = 1;users[i].password[j] = 'o';break;}}}if (flag){modified.push_back(users[i]);}}//输出if (modified.size() == 0){if (users.size() == 1)cout << "There is 1 account and no account is modified" << endl;elsecout << "There are " << N << " accounts and no account is modified" << endl;}else{cout << modified.size() << endl;for (i = 0; i < modified.size(); ++i){cout << modified[i].name << " " << modified[i].password << endl;}}system("pause");return 0;}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 紫睡莲的茎软了怎么办 家养的荷花烂叶怎么办 家养的荷花叶老是枯萎怎么办 新买的绣球蔫了怎么办 绣球花被太阳晒阉了怎么办 羊肉香精放多了怎么办 被飞机防腐剂弄到皮肤怎么办 狗吃了脱氧保鲜剂呕吐怎么办 小孩误吃试纸了保鲜剂怎么办 狗狗把保鲜剂吃了怎么办 小孩吃了防潮珠怎么办 狗吃了防潮剂怎么办 洋桔梗有点烂根怎么办 变色球花枯萎了怎么办 桔梗花叶子蔫了怎么办 洋桔梗头垂下来怎么办 洋桔梗花容易折断怎么办 眼睛被火炮炸伤了怎么办 逆水寒包裹满了怎么办 逆水寒包裹里满了怎么办 grim soul包裹满了怎么办 剑三包裹满了怎么办 电脑开机后都是英文怎么办 欠员工工资仲裁老板不到庭怎么办 乔丹拖鞋鞋底硬怎么办 公牛插座电阻烧了怎么办 公牛led灯太刺眼怎么办 公牛插座usb坏了怎么办 墙壁上开关坏了怎么办 刑事二审判决后不服的怎么办 空调外机空间小怎么办 离婚判决生效书丢了怎么办 法院判决离婚对方上诉怎么办 法院判决离婚上诉中级法院怎么办 刑诉中二审发现一审事实错误怎么办 法院判决过了执行期怎么办 刑事犯罪判决后法院未执行怎么办 法院起诉对方不签字怎么办 法院判离婚对方不要签字怎么办 老人不能到法院签字怎么办 法院判决书被告人没签字怎么办?