题目描述:

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. LeetCode-054-螺旋矩阵

    螺旋矩阵 题目描述:给你一个 m 行 n 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素. 示例说明请见LeetCode官网. 来源:力扣(LeetCode) 链接:http ...

  2. 『现学现忘』Docker基础 — 16、Docker中的基本概念和底层原理

    目录 1.Docker的底层原理 2.Docker中常用的基本概念 3.run命令的运行流程 4.为什么Docker比VM快 Docker架构图: 我们依照Docker架构图进行Docker基础概念的 ...

  3. layui ajax删除

    表单页面 //监听行工具事件 table.on('tool(test)', function(obj){ var data = obj.data; //console.log(obj) if(obj. ...

  4. 面试官:Redis如何实现持久化的、主从哨兵又是什么?

    哈喽!大家好,我是小奇,一位不靠谱的程序员 小奇打算以轻松幽默的对话方式来分享一些技术,如果你觉得通过小奇的文章学到了东西,那就给小奇一个赞吧 文章持续更新 一.前言 作为一名Java程序员,Redi ...

  5. pandas常用操作详解——.loc与.iloc函数的使用及区别

    loc与iloc功能介绍:数据切片.通过索引来提取数据集中相应的行数据or列数据(可以是多行or多列) 总结: 不同:1. loc函数通过调用index名称的具体值来取数据2. iloc函数通过行序号 ...

  6. pd.merge操作的on参数解释

    # 同时传入两个Key,此时会进行以['key1','key2']列表的形式进行对应,left的keys列表是:[['K0', 'K0'],['K0', 'K1'],['K1', 'K0'],['K2 ...

  7. 09 Java的方法 方法的重载 命令行传参

    3.方法的重载 重载就是在一个类中,有相同的函数名称,单形参不同的函数. 方法的重载的规则: 方法名称必须相同. 参数列表必须不同(个数不同.或类型不同.参数排序顺序不同等). 方法的返回类型可以相同 ...

  8. lgP6232题解

    评蓝过分了吧,这题最多黄( 首先我们从挂钩的最上层向下走,假设这个挂杆的左边和右边一共有 \(k\) 件衣服. 若 \(k\) 是 \(2\) 的倍数,那么我们只能向左走(左边和右边的衣服一样多).反 ...

  9. 关于vue3的inheritAttrs属性和$attrs的部分用法

    当我们在父组件中想要为子组件的某一个标签添加一些样式(注意,这里的是指attributes,css样式只是其中一种属性而已) <show-message id="lkx" c ...

  10. Flask 之 WebSocket

    http:是一个协议 规定:数据传输格式 -/r/n/r/n 一次的请求,一次的响应,断开了 短链接 无状态 服务器收到的请求,做出的响应给客户端 客户端主动向服务器发起请求 基于socket sen ...