1035 Password (20 分)

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 Mlines 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

题目大意:由于密码o和0之类很相似,所以给出规则将4种字符进行替换,并且输出替换之后的。

#include <iostream>
#include <vector>
#include <map>
using namespace std; int main() {
int n;
cin>>n;
string na,pd;
map<char,char> mp;
mp['']='@';
mp['']='%';
mp['l']='L';
mp['O']='o';
int ct=;
for(int i=;i<n;i++){
cin>>na>>pd;
bool flag=false;
for(int j=;j<pd.size();j++){
if(mp.count(pd[j])==){
pd[j]=mp[pd[j]];
flag=true;
}
}
if(flag){
cout<<na<<" "<<pd<<'\n';
ct++;
}
}
if(ct==){
if(n==){
cout<<"There is 1 account and no account is modified\n";
}else {
cout<<"There are "<<n<<" accounts and no account is modified\n";
}
}
return ;
}

//第一次提交之后只过了12两个测试点,得5分,这是为什么呢?

AC:

#include <iostream>
#include <vector>
#include <map>
using namespace std; int main() {
int n;
cin>>n;
string na,pd;
map<char,char> mp;
vector<string> vs;
mp['']='@';
mp['']='%';
mp['l']='L';
mp['O']='o';
for(int i=;i<n;i++){
cin>>na>>pd;
bool flag=false;
for(int j=;j<pd.size();j++){
if(mp.count(pd[j])==){
pd[j]=mp[pd[j]];
flag=true;
}
}
if(flag){
//cout<<na<<" "<<pd<<'\n';
vs.push_back(na+" "+pd);
}
}
if(vs.size()==){
if(n==){
cout<<"There is 1 account and no account is modified\n";
}else {
cout<<"There are "<<n<<" accounts and no account is modified\n";
}
}else{
cout<<vs.size()<<'\n';
for(int i=;i<vs.size();i++){
cout<<vs[i]<<'\n';
} }
return ;
}

因为最后那个没输出vs.size()啊。

PAT 1035 Password [字符串][简单]的更多相关文章

  1. PAT 1035 Password

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

  2. pat 1035 Password(20 分)

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

  3. PAT 甲级 1035 Password (20 分)(简单题)

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

  4. 【PAT】1035. Password (20)

    题目:http://pat.zju.edu.cn/contests/pat-a-practise/1035 分析:简单题.直接搜索,然后替换,不会超时,但是应该有更好的办法. 题目描述: To pre ...

  5. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

  6. PAT 甲级 1035 Password (20 分)

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

  7. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  8. 1035 Password (20 分)

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

  9. FJ的字符串-简单递归

    FJ的字符串-简单递归 问题描述FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = “ABA” A3 = “ABACABA” A4 = “ABACABADABACABA” … … 你能找出其 ...

随机推荐

  1. STL源代码剖析——STL算法stl_algo.h

    前言 在前面的博文中剖析了STL的数值算法.基本算法和set集合算法.本文剖析STL其它的算法,比如排序算法.合并算法.查找算法等等.在剖析的时候.会针对函数给出一些样例说明函数的使用.源代码出自SG ...

  2. The Definitive Guide To Django 2 学习笔记(六) 第四章 模板 (二)使用模板系统

    模板系统不是django特有的,它是python的一个库,你可以在任何地方使用它. 使用方法: 1.使用 Template()方法创建Template对象.2.调用Template对象的render( ...

  3. 怎么来爬取代理服务器ip地址?

    一年前突然有个灵感,想搞个强大的网盘搜索引擎,但由于大学本科学习软件工程偏嵌入式方向,web方面的能力有点弱,不会jsp,不懂html,好久没有玩过sql,但就是趁着年轻人的这股不妥协的劲儿,硬是把以 ...

  4. 查看网络连接数目(解决TIME_WAIT过多造成的问题_转)

      转自:解决TIME_WAIT过多造成的问题 (eroswang的csdn) #netstat -n | awk '/^tcp/ {++S[$NF]} END { for(a in S) print ...

  5. IPC之共享内存

    man 7 shm_overview shm_overview - Overview of POSIX shared memory. 同样,SystemV实现的共享内存是旧的机制,但应用广泛:Posi ...

  6. AVCapture编程理解

    AVCapture用于媒体采集,在媒体采集的流程中,会存在如下几个对象: AVCaptureDevice.这里代表抽象的硬件设备. AVCaptureInput.这里代表输入设备(可以是它的子类),它 ...

  7. 初识Python、PyCharm、Anaconda与tensorflow

    最近裸辞了,未来希望转深度学习.语音识别.文本挖掘,觉得这块特别有意思,比较好玩.开始自学相关知识,为了能够独立地.系统地了解和学习相关知识,计划不定期记录和更新一些平时的学习总结,个人关于以上几个方 ...

  8. <!>字体效果

    <h1>...</h1>标题字(最大) <h6>...</h6>标题字(最小) <b>...</b>粗体字 <strong ...

  9. AWS系列-申请MySQL

    1.1 打开aws控制台,可以直接搜索MySQL 1.2 打开MySQL(rds)控制面板 点击启动数据库实例(这个只是启动创建的意思,不是启动下面创建好的node.我也不懂为啥翻译过来是这个意思.. ...

  10. iOS UITextView 输入内容实时更新cell的高度

    iOS UITextView 输入内容实时更新cell的高度 2014-12-26 11:37 编辑: suiling 分类:iOS开发 来源:Vito Zhang'blog  11 4741 UIT ...