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[+ ...
随机推荐
- 图解|从根上彻底理解MySQL的索引
这是图解MySQL的第4篇文章,这篇文章会让你 明白什么是索引,彻底理解B+树和索引的关系: 彻底理解主键索引.普通索引.联合索引: 了解什么是HASH索引,InnoDB和MyISAM索引的不同实现方 ...
- thinkPHP ajax 状态修改(上架修改为下架)
<td> {if $v.status==1} <span class="top{$v.id}" name="0" onclick=" ...
- 字节一面:go的协程相比线程,轻量在哪?
1. 用户态和内核态 Linux整个体系分为用户态和内核态(或者叫用户空间和内核空间), 那内核态究竟是什么呢? 本质上我们所说的内核态, 它是一种特殊的软件程序,特殊在哪? 统筹计算机的硬件资源,例 ...
- 华为交换机配置telnet、SSH
如果网络中有一台或多台网络设备需要远程进行配置和管理,可以通过Telnet远程连接到每一台设备上,对这些网络设备进行集中的管理一维护. 一.AAA认证Telnet服务端 1.配置接口信息 <Hu ...
- 变量、变量作用域、常量final、变量的命名规范
变量 变量是什么:就是可以变化的量! Java是一种强类型语言,每个变量都必须声明其类型. Java变量是程序中最基本的存储单元,其要素包括变量名,变量类型和作用域. 注意事项: 每个变量都有类型,类 ...
- ArcGIS修路问题(最优路径问题)
1 前言 修路问题,辅助减少花费.用栅格进行路径分析. 2 问题阐述 根据题目要求,找出一条从学校通往某目的地的道路,实现以下操作: (1)坡度在30度以上的地形不适合修建道路,适合修路的坡度相等间隔 ...
- Jmeter beanshell把数据写入csv文件中,最后清除csv数据
有时候我们需要使用jmeter去结合csv文件去做一些简单的数据驱动处理: 例如把数据库数据黏贴到csv文件中或者把网页上的数据填入到csv文件中: 直接我一般是用手自己黏贴复制过csv文件中,比较麻 ...
- Python:range、np.arange和np.linspace
1. range range是python内置的一个类,该类型表示一个不可改变(immutable)的数字序列,常常用于在for循环中迭代一组特殊的数,它的原型可以近似表示如下: class rang ...
- 如何解决代码中if/else 过多的问题
前言 if...else 是所有高级编程语言都有的必备功能.但现实中的代码往往存在着过多的 if...else.虽然 if...else 是必须的,但滥用 if...else 会对代码的可读性.可维护 ...
- python psutila模块
#!/usr/bin/env python #coding:utf-8 # qianxiao996精心制作 #博客地址:https://blog.csdn.net/qq_36374896 import ...