PAT A1035 Password
题目描述:
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
题目大意:输入n组数据,第一个字符串为数据编号,第二个字符串为需要修改的密码。如果第二个字符串中有1就替换成@,0替换成%,l替换成L,O替换成o
如果有密码被修改,输出修改的数量已经修改过的密码的编号和修改后的密码。如果没有修改,则需要输出(注意输出的单复数!)
There is 1 account and no account is modified 或者
There are N accounts and no account is modified
解题思路:
(1)将编号和密码用一个结构体来封装,同时包含一个是否修改的标志。
(2)对输入的数据进行处理,遇到需要替换的就替换,并把修改标志改为true,否则的话修改标志位false。
(3)用一个计数器记录修改的数量,初值为n,遇到一个未修改的,就将num--,最终num如果为0,说明没有元素被修改,num不为0时,输出num,并且输出修改标志位为true的数据。
#include<iostream>
using namespace std;
struct Password {
char id[12];
char pass[12];
bool isChange;
}p[1001];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i].id >> p[i].pass;
}
int num = n;//计算有多少个被修改
for (int i = 0; i < n; i++) {
//对密码进行修改
for (int j = 0; j < strlen(p[i].pass);j++) {
if (p[i].pass[j] == '1') {
p[i].pass[j] = '@';
p[i].isChange = true;
}
else if (p[i].pass[j] == '0') {
p[i].pass[j] = '%';
p[i].isChange = true;
}
else if (p[i].pass[j] == 'l') {
p[i].pass[j] = 'L';
p[i].isChange = true;
}
else if (p[i].pass[j] == 'O') {
p[i].pass[j] = 'o';
p[i].isChange = true;
}
}
if (p[i].isChange != true) {
//没有被修改的话,num--
p[i].isChange = false;
num--;
}
}
if (num == 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;
}
}
else {
//有数据被修改
cout << num << endl;
for (int i = 0; i < n; i++) {
//只输出被修改的内容
if (p[i].isChange) {
cout << p[i].id << " " << p[i].pass << endl;
}
}
}
system("pause");
return 0;
}
PAT A1035 Password的更多相关文章
- PAT A1035 Password (20)
AC代码 注意创造函数条件中使用引用 输出语句注意单复数 #include <cstdio> #include <cstring> #include <iostream& ...
- A1035 Password (20)(20 分)
A1035 Password (20)(20 分) To prepare for PAT, the judge sometimes has to generate random passwords f ...
- PAT甲级——A1035 Password
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- A1035. Password
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- PAT 1035 Password
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- PAT 1035 Password [字符串][简单]
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- pat 1035 Password(20 分)
1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...
- PAT题目AC汇总(待补全)
题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...
- PAT/字符串处理习题集(二)
B1024. 科学计数法 (20) Description: 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+ ...
随机推荐
- SQL从零到迅速精通【数据更新】
1.[导入表]在两个表的格式一样的情况下,将一个表的数据导入另外一个表. person_old表中现在有两条记录.接下来将person_old表中所有的记录插入到person表中,语句如下: INSE ...
- 【转载】SQL实例大全
from:http://blog.csdn.net/basycia/article/details/52134279 OR from:http://www.cnblogs.com/yubinfeng/ ...
- 支持向量机(SVM):用一条线分开红豆与绿豆
算法原理 要找到一些线,这些线都可以分割红豆和绿豆,找到正确的方向或者斜率的那条线,确认马路的宽度,得到最优解--马路的中轴 超平面:在三维空间中,平面是两个点距离相同的点的轨迹.一个平面没有厚度,而 ...
- Netty异步Future源码解读
本文地址: https://juejin.im/post/5df771ee6fb9a0161d743069 说在前面 本文的 Netty源码使用的是 4.1.31.Final 版本,不同版本会有一些差 ...
- 01 简介 如何高效的学习Java
JavaSE 千寻简学习笔记 简介 TIOBE:编程语言排行榜 官网:https://hellogithub.com/report/tiobe/ 如何高效的学习Java 多写(代码)多写(笔记)多写( ...
- Docker容器和虚拟机区别
Docker .虚拟机之间区别 虚拟机技术的缺点: 1.资源占用太多 2.冗余步骤多 3.启动很慢 容器化技术 1.服务器资源利用率高 2.比较轻量化 3.打包镜像测试,一键运行 比较Docker和虚 ...
- 什么是CSRF跨站请求伪造?(from表单效验csrf-ajdax效验csrf-Ajax设置csrf-CBV装饰器验证csrf)
目录 一:csrf跨站请求伪造 1.什么是CSRF? 2.CSRF攻击案例(钓鱼网站) 3.钓鱼网站 内部原理 4.CSRF原理(钓鱼网站内部本质) 5.从上图可以看出,要完成一次CSRF攻击,受害者 ...
- CSS性能优化的几个技巧
前言 随着互联网发展至今,对于网站来说,性能显的越来越重要了,CSS作为页面渲染和内容展现的重要环节,影响着用户对整个网站的第一体验.所以,我们需要重视与CSS相关的性能优化. 项目开发初期我们可能因 ...
- linux如何通过文件2,3找回文件1?
查看系统是否有diff,patch命令 diff一般系统自带 patch下载 (yum install patch -y) 现在开始演示 我的系统里有1和2两个文件 使用 diff 1 2 > ...
- phpcms手工注入教程
目标服务器(靶机):192.168.1.27 目标网站:http://192.168.1.27:8083 步骤: 一.靶机操作 1.进入靶机,查看IP地址: 开始-运行,输入cmd回车,出现命令行窗口 ...