PAT 甲级 1035 Password
https://pintia.cn/problem-sets/994805342720868352/problems/994805454989803520
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
代码:
#include <bits/stdc++.h>
using namespace std; char username[20], pw[20];
char userr[1111][20], pww[1111][20];
char s1[5] = {'1', '0', 'l', 'O'};
char s2[5] = {'@', '%', 'L', 'o'}; int yes(char a[20]) {
int len = strlen(a);
bool flag = false;
for(int i = 0; i < len; i ++) {
for(int j = 0; j <= 3; j ++) {
if(a[i] == s1[j])
flag = true;
}
}
if(flag) return 1;
else return 0;
} int main() {
int n;
scanf("%d", &n);
int cnt = 0;
for(int i = 1; i <= n; i ++) {
scanf("%s%s", username, pw);
cnt += yes(pw);
if(yes(pw) == 1) {
strcpy(userr[cnt], username);
int lenn = strlen(pw);
for(int j = 0; j < lenn; j ++) {
for(int k = 0; k <= 3; k ++) {
if(pw[j] == s1[k])
pw[j] = s2[k];
}
}
strcpy(pww[cnt], pw);
}
} if(cnt == 0) {
if(n == 1)
printf("There is 1 account and no account is modified\n");
else
printf("There are %d accounts and no account is modified\n", n);
} else {
printf("%d\n", cnt);
for(int i = 1; i <= cnt; i ++)
printf("%s %s\n", userr[i], pww[i]);
} return 0;
}
PAT 甲级 1035 Password的更多相关文章
- PAT 甲级 1035 Password (20 分)
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 ...
- PAT甲级——1035 Password (20分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- 【PAT】1035. Password (20)
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1035 分析:简单题.直接搜索,然后替换,不会超时,但是应该有更好的办法. 题目描述: To pre ...
- PAT Advanced 1035 Password (20 分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- PAT甲级——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 ...
随机推荐
- 01-Python简介
人生苦短,我用 Python —— Life is short, you need Python 目标 Python 的起源 Python 解释器 是用 C 语言实现的,并能够调用 C 语言的库文件. ...
- 数据结构与算法之排序(2)选择排序 ——in dart
选择排序的算法复杂度与冒泡排序类似,其比较的时间复杂度仍然为O(N2),但减少了交换次数,交换的复杂度为O(N),相对冒泡排序提升很多.算法的核心思想是每次选出一个最小的,然后与本轮循环中的第一个进行 ...
- 第十四周 P187教材检查
在IDEA中或命令行中运行P187 Guess.java. 这道题是继承语法抽象类一块的知识点,题目本身其实并不难,但是当时做的时候我找自己原来的代码花了很长时间,刚找到运行完截好图,就到时间了. 当 ...
- 20155226-虚拟机与Linux之初体验
虚拟机与Linux之初体验 虚拟机的安装 虚拟机对我来说不是很了解,但今天在安装过程中加深了我的理解.虚拟机是一个在原来系统基础上进行的又一个系统安装,可以在不影响前者的情况下完成一些其不能解决的问题 ...
- 20155323刘威良第一次实验 Java开发环境的熟悉(Linux + IDEA)
20155323刘威良第一次实验 Java开发环境的熟悉(Linux + IDEA) 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序 ...
- 图解Oracle下建立tnsname
第一步:运行netca: 第二步: 第三步: 第四步: 第五步: 第六步: 如果前面设置都正确,测试的结果将正常(前提是Database的listener要开启).
- 【LG3243】[HNOI2015]菜肴制作
题面 洛谷 题解 首先我们有个非常显然的思路, 就是直接拓扑排序,用小根堆代替队列再按顺序输出,但是很显然是错的, 因为这只保证了字典序最小,而无法保证答案最优,\(<2,4>,<3 ...
- Repo 的使用小结
一.安装 创建目录和修改环境变量 $ mkdir ~/bin $ PATH=~/bin:$PATH 下载repo代码 $ curl https://storage.googleapis.com/git ...
- C#之Ref,Out以及TryParse()的用法
ref和out用法很简单,我记下来也提醒自己要用更好的方式去写代码,不要让代码过于臃肿,让人看得头痛.直接写 ref:ref关键字就是让参数进行传递,但是需要初始化,而out不需要初始化参数 ref用 ...
- php引用&使用笔记
引用与赋值是两个概念:引用是共用同一个内存地址,一个改变其他也会变,赋值是另外开辟内存空间,一个改变其他不会变 一个简单例子: $a=123; //$a开辟一个内存空间存储123 $b=&$a ...