A1035Password

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 (≤), 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:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

Sample Output 1:

2
Team000002 RLsp%dfa
Team000001 R@spodfa

Sample Input 2:

1
team110 abcdefg332

Sample Output 2:

There is 1 account and no account is modified

Sample Input 3:

2
team110 abcdefg222
team220 abcdefg333

Sample Output 3:

There are 2 accounts and no account is modified

思路:

• 定义结构体,每输入一组数据判断是否需要修改,若需要修改然后做出修改,计数cnt++,将修改后的数据存入结构体数组;

• 若cnt!=0,则输出cnt和结构体数组;若cnt==0,则判断n是否等于1,做出不同输出。

 

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 struct Students
 5 {
 6     string name;
 7     string pass;
 8 };
 9 int main() {
10     Students stu[1005];
11     int n, cnt = 0;;
12     string namei, passi;
13     bool tag = 0;
14     cin >> n;
15     for (int i = 0; i < n; i++) {
16         cin >> namei >> passi;
17         for (int j = 0; j < passi.length(); j++) {
18             if (passi[j] == '1') {
19                 passi[j] = '@';
20                 tag = 1;
21             }
22             if (passi[j] == 'l') {
23                 passi[j] = 'L';
24                 tag = 1;
25             }
26             if (passi[j] == '0') {
27                 passi[j] = '%';
28                 tag = 1;
29             }
30             if (passi[j] == 'O') {
31                 passi[j] = 'o';
32                 tag = 1;
33             }
34         }
35         if (tag == 1) {
36             stu[cnt].name = namei;
37             stu[cnt].pass = passi;
38             cnt++;
39             tag = 0;
40         }
41     }
42     if (cnt!=0) {
43         cout << cnt << endl;
44         for (int i = 0; i < cnt; i++) {
45             cout << stu[i].name << " " << stu[i].pass << endl;
46         }
47     }
48     else {
49         if (n == 1)
50             printf("There is 1 account and no account is modified");
51         else
52             printf("There are %d accounts and no account is modified", n);
53     }
54     return 0;
55 }

 

posted @ 2020-02-11 18:25  PennyXia  阅读(132)  评论(0编辑  收藏  举报