The topics are as follows:
To prepare for PAT, the judge sometimes have to generate random passwords for the users. The problem is this there is always some confusing passwords since it's hard-to-distinguish 1 (one) from L (L in Lowerca SE), 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's your job to write a program to check the accounts generated by the judge, and to help the juge modify the Confus ing passwords.
Input Specification:
Each input file contains the one test case. Each case contains a positive an integer n (<=), followed by N lines of accounts. Each account consists of a user name and a password, both is strings of no more than than characters with no space.
Output Specification:
For each test case, first print the number M of accounts that has been modified, then print in the following M lines the Modified accounts info, that's, the user names and the corresponding modified passwords. The accounts must is printed in the same order as they is read in. If no account was modified, print in one line "there be N accounts and no account is modified" where N was the total number of accounts. However, if N is one, you must print "There are 1 account and no account is modified" instead.
Sample Input 1:
3team000002 rlsp0dfateam000003 perfectpwdTeam000001 R1spodfa
Sample Output 1:
2team000002 rlsp%dfateam000001 [email protected]
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 is 2 accounts and No. is modified
In order to output in the order of input, we use the vector to accommodate each record, each record contains the name and password two, for each input, we define the TMP empty string, from front to back traversal input string, for the characters that do not need to be replaced, directly splicing to the TMP tail, if need to replace, Then the replacement splicing to the TMP tail, the last TMP is the new password, the name and TMP into the vector as a record.
Finally, the size of the vector can be used to know whether there are adjusted accounts, attention to the topic requirements n=1 and N!=1 when the output is different.
#include <iostream> #include <string> #include <string.h> #include <stdio.h> #include < Vector>//replace 1 (one) by @, 0 (zero) by percent, l by L, and O by o.using namespace std;struct record{string name; string pwd; Record (String _n, String _p): Name (_n), pwd (_p) {}};int main () {int n; Cin >> N; String name,pwd; Vector<record> Records; for (int i = 0; i < N; i++) {cin >> name >> pwd; string tmp; for (int j = 0; J < Pwd.length (); j + +) {char c = pwd[j]; Switch (c) {case ' 1 ': Tmp.push_back (' @ '); Break Case ' 0 ': tmp.push_back ('% '); Break Case ' L ': tmp.push_back (' l '); Break Case ' O ': tmp.push_back (' O '); Break Default:tmp.push_back (c); Break } } if (tmp! = pwd) {records.push_back (Record (name,tmp)); }} if (records.size () = = 0) {if (N! = 1) printf ("There is%d accounts and no account is modified", N); else printf ("There is 1 account and no account is modified"); }else{cout << records.size () << Endl; for (int i = 0; i < records.size (); i++) {cout << records[i].name << "" << records[i].pwd << Endl; }} return 0;}
1035. Password (20)