题目描述:

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的更多相关文章

  1. PAT A1035 Password (20)

    AC代码 注意创造函数条件中使用引用 输出语句注意单复数 #include <cstdio> #include <cstring> #include <iostream& ...

  2. A1035 Password (20)(20 分)

    A1035 Password (20)(20 分) To prepare for PAT, the judge sometimes has to generate random passwords f ...

  3. PAT甲级——A1035 Password

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  4. A1035. Password

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  5. PAT 1035 Password

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

  6. PAT 1035 Password [字符串][简单]

    1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...

  7. pat 1035 Password(20 分)

    1035 Password(20 分) To prepare for PAT, the judge sometimes has to generate random passwords for the ...

  8. PAT题目AC汇总(待补全)

    题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...

  9. PAT/字符串处理习题集(二)

    B1024. 科学计数法 (20) Description: 科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式[+-][1-9]"."[0-9]+E[+ ...

随机推荐

  1. Golang开源流媒体服务器(RTMP/RTSP/HLS/FLV等协议)

    一. lal 简介 lal是开源直播流媒体网络传输项目,主要由三部分组成: lalserver:流媒体转发服务器.类似于nginx-rtmp-module等服务,但支持更多的协议,提供更丰富的功能. ...

  2. MATLAB神经网络应用设计【2】

    一.深度学习中经常看到epoch. iteration和batchsize,下面按自己的理解说说这三个的区别: (1)batchsize:批大小.在深度学习中,一般采用SGD训练,即每次训练在训练集中 ...

  3. PC微信聊天记录数据迁移恢复

    PC微信聊天记录数据迁移恢复   本文章仅仅是PC微信聊天记录从一台电脑迁移到另外一台电脑恢复办法,主要适用于更换电脑,或重装系统,用户想保存PC微信中数据和文件. 1.查看微信记录的保存文件夹 设置 ...

  4. 201922904李龙威 2019-2020-2 《Python程序设计》实验二报告

    20192204 2019-2020-2 <Python程序设计>实验二报告 课程:<Python程序设计> 班级: 1922 姓名: 李龙威 学号:20192204 实验教师 ...

  5. BSOJ6310题解

    互不相同,太困难啦!!!!!! 考虑可以相同的情况.可以容斥. \[ans=(1+1+1+1)-(2+1+1)+(3+1)+(2+2)-(4) \] 有点抽象,看看就好() \[ans=(a,b,c, ...

  6. django的request对象方法初识

    1:request.post 拿到的是post请求发送过来的数据,可以将其看作是一个个的键值对 使用get方法可以通过key拿到值,如果该值是一个列表的话,get方法只能拿到列表的最后一个值,使用ge ...

  7. unity 加载网络图片

    摘要:利用Http加载网络图片. 解决思路: 1.直接用unity 自带的www加载,在高版本www已经过时了. 2.本文直接使用万能的文件流加载. (1)使用System.Net.HttpWebRe ...

  8. k8s 开船记-脚踏两只船:船儿还是旧的好,不翻船才是硬道理

    自从上次开始脚踏两只船(2个独立的k8s集群同时运行),园子暂时用奢侈的土豪方式过上了安稳的船上生活. 这种方式除了费钱之外,还带来一个问题,我们的集装箱自动装船系统(基于gitlab-ci的自动化部 ...

  9. Java多线程【三种实现方法】

    java多线程 并发与并行 并发:在操作系统中,是指一个时间段中有几个程序都处于已启动运行到运行完毕之间,且这几个程序都是在同一个处理机上运行,但任一个时刻点上只有一个程序在处理机上运行 并行:一组程 ...

  10. APIO2015 八邻旁之桥/巴邻旁之桥

    题目描述: bz luogu 题解: 贪心+权值线段树. $K=1$的时候,答案为$\sum |x-l| + |x-r|$,所以所有端点排序后取中位数即可. $K=2$的时候,一定是左边的一些走左边的 ...