1035 Password
2021/6/27 6:15:51
本文主要是介绍1035 Password,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
题目来源:PAT (Advanced Level) Practice
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 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
words:
confusing 难以理解的,不清楚的 distinguish 区分,辨别 replace 替换,取代
modify 修改,调整 judge 判断,评判 consists of 由…组成 corresponding 相应的
思路:
1. 对于密码中含有难以识别的的字符时用其他字符替代;1用@、l 用L、0用%、O用o替换;
2. 把替换后的密码和其用户名保存到一个数组p中,并用k记录个数,若没有任何替换则不保存;
3.若所有的输入都没有发生替换,则当n==1时,输出“There is 1 account and no account is modified
”,当n>1时输出“There are N accounts and no account is modified"
;
4.否则有发生替换则首先输出替换的密码个数k,然后按输入顺序替输出替换后的密码和用户名,即数组p中的元素;(没有替换的元素则无需输出)
//PAT ad 1035 Password #include <iostream> using namespace std; #define N 1000 pair<string,string> p[N]; //记录发生替换的用户名和密码 int k=0; void needToModify(string name,string password) //检测密码是否需要修改并修改 { int c=0,i; for(i=0;i<password.size();i++) { switch(password[i]) { case '1':password[i]='@';break; case '0':password[i]='%';break; case 'l':password[i]='L';break; case 'O':password[i]='o';break; default:c++; } } if(c==i) return ; //没有发生替换 p[k++]={name,password}; } int main() { int n,i; cin>>n; string name,password; for(i=0;i<n;i++) //输入 { cin>>name>>password; needToModify(name,password); } if(k==0) //没有要修改时的输出 { 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; //大于1用单词用复数形式 } else //有修改时的输出 { cout<<k<<endl; for(i=0;i<k;i++) cout<<p[i].first<<" "<<p[i].second<<endl; } return 0; }
这篇关于1035 Password的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)