题目链接:点击打开链接
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:
3 Team000002 Rlsp0dfa Team000003 perfectpwd Team000001 R1spOdfaSample Output 1:
2 Team000002 RLsp%dfa Team000001 R@spodfaSample Input 2:
1 team110 abcdefg332Sample Output 2:
There is 1 account and no account is modifiedSample Input 3:
2 team110 abcdefg222 team220 abcdefg333Sample Output 3:
There are 2 accounts and no account is modified注意事项:只检测一个密码且这个密码合格时输出:
There is 1 account and no account is modified
检测多个密码且密码全合格时输出:
There are 2 accounts and no account is modified我的C++程序:
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; bool is_1(char c)//如果字符是1 { return c == '1'; } bool is_0(char c)//如果字符是0 { return c == '0'; } bool is_l(char c)//如果字符是l { return c == 'l'; } bool is_O(char c)//如果字符是O { return c == 'O'; } bool is_bad_pwd(string str)//判断密码是否含有 1,0,l,O中的字符,含有则返回1 { string pwd; pwd = str.substr(str.find(' ') + 1, str.size() - 1); if (pwd.find('1') == -1 && pwd.find('0') == -1 && pwd.find('l') == -1 && pwd.find('O') == -1) { return 0; } return 1; } void change_and_print(string str) { string pwd; pwd = str.substr(str.find(' ') + 1, str.size() - 1); replace_if(pwd.begin(), pwd.end(), is_1, '@');//找到所有'1',并替换为'@' replace_if(pwd.begin(), pwd.end(), is_0, '%');//replace_if头文件<algorithm> replace_if(pwd.begin(), pwd.end(), is_l, 'L'); replace_if(pwd.begin(), pwd.end(), is_O, 'o'); cout <<str.substr(0,str.find(' ')+1)+pwd<<endl;//输出帐户名+空格+修改后的密码 } int main() { int n; int i = 0; string s,account,pwd; vector<string>str; int count_unfit= 0;//不合适的密码数量 cin >> n; if (n == 0) { return 0; } for (i = 0;i <n;i++) { cin >> account >> pwd;//输入账户名和密码 s = account +' '+ pwd;//帐户名+空格+密码合并为一个字符串 str.push_back(s);//加入到vector } for (i = 0;i < n;i++) { if (is_bad_pwd(str[i]) == 1)//判断不合适的密码 count_unfit++;//不合适的密码数量+1 } if (count_unfit > 0) cout << count_unfit << endl;//输出不合适的密码数量 for (i = 0;i <n;i++) { if (is_bad_pwd(str[i]) == 1)//如果是不合适的密码 change_and_print(str[i]);//输出账号和修改后的密码 } if (count_unfit==0)//如果密码全部合格 { if(n==1)//密码全部合格,且只检测一个时 printf("There is 1 account and no account is modified", n); else//多个账号和密码合格 printf("There are %d accounts and no account is modified", n); } //system("pause"); return 0; }