PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642
PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642
题目描述:
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 judge modify the confusing passwords.
译:为了准备 PAT , 裁判们有时候不得不为用户生成随机的密码。这样的问题就是经常会出现许多混乱的密码,因为很难区分 1(1) 和 l (L 的小写) , 0 (0) 和O (o 的大写)。一种解决办法就是用 @ 代替 1 , % 代替 0 , L 代替 l , O代替 o。现在你的任务就是写一个程序检查裁判生成的账号,并帮助裁判修改这混乱的密码。
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.
译:每个输入文件包含一个测试用例,每个用例包含一个正整数 N (≤1000), 紧跟着 N 行账号。每个账号包含一个 用户名 和一个密码,并且都是不超过十个字符并且不含空白符的字符串
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.
译:对于每个测试用例,第一行输出被修改过的账号的数量 M,然后接下来 M 行打印修改过的账号信息,也就是说,用户名对应的修改过的密码。账号的输出顺序必须和输入顺序一致。如果没有账号被修改,在一行中打印 There are N accounts and no account is modified 其中 N 表示 账号的总数。但是,如果 N 等于 1的话,你必须输出 There is 1 account and no account is modified 。
Sample Input 1 (样例输入1):
3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa
Sample Output 1 (样例输出1):
2
Team000002 RLsp%dfa
Team000001 R@spodfa
Sample Input 2 (样例输入2):
1
team110 abcdefg332
Sample Output 2 (样例输出2):
There is 1 account and no account is modified
Sample Input 3 (样例输入3):
2
team110 abcdefg222
team220 abcdefg333
Sample Output 3 (样例输出3):
There are 2 accounts and no account is modified
The Idea:
设计到字符串,由于需要存储一个 name - passwd 的键值对, 本来首选是使用 map 来进行键值对的处理,但是map会自动排序,与要求输出顺序需要喝输入顺序不同相矛盾,故采取了用 vector来存储 pair 类型数据。值得注意的是,题目中明确说明了 n = 1 和 n != 1的时候的情况输出是不同的,特别注意 are 和 is 还有 account 和 accounts 这里有坑(测试点2) .
The Codes:
#include<bits/stdc++.h>
using namespace std ;
string name , passwd1 , passwd2 ;
int n ;
vector<pair<string , string> > ans ; // 利用 pair 捆绑 name 和 passwd
string modify(string s){
string str = "" ;
for(int i = 0 ; i < s.size() ; i ++){
if(s[i] == '1') str += '@' ; // 如果是 1 替换成 @
else if(s[i] == '0') str += '%' ; // 如果是 0 替换成 %
else if(s[i] == 'l') str += 'L' ; // 如果是 l 替换成 L
else if(s[i] == 'O') str += 'o' ; // 如果是 O 替换成 o
else str += s[i] ; // 其他的直接连接
}
return str ;
}
int main(){
scanf("%d" , &n) ;
for(int i = 0 ; i < n ; i ++){
cin >> name >> passwd1 ;
passwd2 = modify(passwd1) ;
if(passwd1 != passwd2) ans.push_back(make_pair(name , passwd2)) ;// 修改的加入向量
}
if(ans.size() == 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" , ans.size()) ;
for(int i = 0 ; i < ans.size() ; i ++)
printf("%s %s\n" , (ans[i].first).c_str() , (ans[i].second).c_str()) ;
}
return 0;
}
PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642的更多相关文章
- PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642
PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...
- PAT (Advanced Level) Practice 1035 Password (20 分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- PAT (Advanced Level) Practice 1008 Elevator (20 分) (模拟)
The highest building in our city has only one elevator. A request list is made up with N positive nu ...
- PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642
PAT (Advanced Level) Practice 1046 Shortest Distance (20 分) 凌宸1642 题目描述: The task is really simple: ...
- PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分) 凌宸1642 题目描述: Shuffling is a procedure us ...
- PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642
PAT (Advanced Level) Practice 1041 Be Unique (20 分) 凌宸1642 题目描述: Being unique is so important to peo ...
- PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642
PAT (Advanced Level) Practice 1031 Hello World for U (20 分) 凌宸1642 题目描述: Given any string of N (≥5) ...
- PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642
PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...
- PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642
PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...
随机推荐
- js uppercase the first letter of string
js uppercase the first letter of string js String.toUpperCase `-webkit-border-image`.split(`-`).filt ...
- how to install zoom meeting app in macOS
how to install zoom meeting app in macOS https://support.zoom.us/hc/zh-cn/articles/203020795-如何在Mac上 ...
- 超详细Openstack核心组件——nova部署
目录 OpenStack-nova组件部署 nova组件部署位置 计算节点Nova服务配置(CT配置) 计算节点配置Nova服务-c1节点配置 计算节点-c2(与c1相同)(除了IP地址) contr ...
- 【python】递归听了N次也没印象,读完这篇你就懂了
听到递归总觉得挺高大上的,为什么呢?因为对其陌生,那么今天就来一文记住递归到底是个啥. 不过先别急,一起来看一个问题:求10的阶乘(10!). 求x的阶乘,其实就是从1开始依次乘到x.那么10的阶乘就 ...
- 2021年-在windwos下如何用TOMACT发布一个系统(完整配置案列)
2021年新年第一篇:博主@李宗盛-关于在Windwos下使用TOMCAT发布一个系统的完成配置案列. 之前写过关于TOMCAT的小篇幅文档,比较分散,可以作为对照与参考. 此篇整合在一起,一篇文档写 ...
- javascript 十大经典排序
首先生成一个数字数组: let arr = Array.from({length:20},x=>{return Math.ceil(Math.random()*10**2)}) console. ...
- Django自学计划之集装箱货物运输物流仓储一站式ERP系统
业余开始学习时间:2018年1月 业余学习时间段:每天下班晚饭后时间+无事的星期六和星期天+上班时的空闲时间 自学目标: 1.我们要用管理的思维来写我们的系统! 2.我们要用我们的ERP系统帮助中小集 ...
- 使用Docker快速搭建Nginx+PHP-FPM+MySQL+phpMyAdmin环境
一.概述 环境介绍 操作系统:centos 7.6 docker版本:19.03.8 ip地址:192.168.31.34 本文将介绍如何使用单机部署Nginx+PHP-FPM环境 二.Nginx+P ...
- 图解CyclicBarrier运动员接力赛
图解游戏规则 大家都知道运动员短跑接力赛,今天我们并不是讲接力赛,我们讲"接力协作赛",需要我们重新定义下游戏规则:如下图所示 现在有运动员A,B,先定义游戏规则:赛道目前是300 ...
- ASP.NET如何把ASPX网站部署到IIS上
当一个项目完成了,你是否想过把它发布到服务器上去呢?那么下面就来告诉你如何去部署它吧! (Visual Studio版本: 2019) 首先要准备好你的项目 然后进行如下操作 第一大步骤 1.打开你需 ...