problem

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

tip

简单字符串处理

answer

#include<iostream>
#include<vector>
using namespace std; int N;
vector<string > v;
bool Replace(string &s){
bool flag = false;
for(int j = 0; j < s.size(); j++){
// if(t[i] == '1') {
// t[i] = '@';
// flag = true;
// }
// if(t[i] == '0'){
// t[i] = '%';
// flag = true;
// }
//
// if(t[i] == 'l'){
// t[i] = 'L';
// flag = true;
// }
// if(t[i] == 'O'){
// t[i] = 'o';
// flag = true;
// }
switch(s[j]) {
case '1' : s[j] = '@'; flag = true; break;
case '0' : s[j] = '%'; flag = true; break;
case 'l' : s[j] = 'L'; flag = true; break;
case 'O' : s[j] = 'o'; flag = true; break;
}
}
return flag;
}
int main(){
// freopen("test.txt", "r", stdin);
cin>>N;
for(int i = 0; i < N; i++){
string a, p;
cin>>a>>p;
if(Replace(p)) {
string aa = a + " " + p;
v.push_back(aa);
}
}
if(v.size()){
printf("%d\n", v.size());
for(int i = 0; i < v.size(); i++){
cout<<v[i]<<endl;
}
}else if(v.size() == 0) {
if(N == 1) cout<<"There is "<<N<<" account and no account is modified"<<endl;
else printf("There are %d accounts and no account is modified", N);
}
return 0;
}

experience

  • 这种题目应该尽量复制粘贴题目中的信息,血的教训。

1035 Password (20)(20 point(s))的更多相关文章

  1. A1035 Password (20)(20 分)

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

  2. PAT 甲级 1011 World Cup Betting (20)(20 分)

    1011 World Cup Betting (20)(20 分)提问 With the 2010 FIFA World Cup running, football fans the world ov ...

  3. PAT 甲级 1001 A+B Format (20)(20 分)

    1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...

  4. PAT 1049 数列的片段和(20)(代码+思路分析)

    1049 数列的片段和(20)(20 分) 给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段.例如,给定数列{0.1, 0.2, 0.3, 0.4},我们有(0.1) (0.1, 0.2 ...

  5. PAT 1033 旧键盘打字(20)(20 分)

    1033 旧键盘打字(20)(20 分) 旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现.现在给出应该输入的一段文字.以及坏掉的那些键,打出的结果文字会是怎样? 输入格式: 输入在2 ...

  6. 【PAT】1019 数字黑洞 (20)(20 分)

    1019 数字黑洞 (20)(20 分) 给定任一个各位数字不完全相同的4位正整数,如果我们先把4个数字按非递增排序,再按非递减排序,然后用第1个数字减第2个数字,将得到一个新的数字.一直重复这样做, ...

  7. PAT 1054 求平均值 (20)(代码+思路+测试用例)

    1054 求平均值 (20)(20 分) 本题的基本要求非常简单:给定N个实数,计算它们的平均值.但复杂的是有些输入数据可能是非法的.一个"合法"的输入是[-1000,1000]区 ...

  8. 【PAT】1018 锤子剪刀布 (20)(20 分)

    1018 锤子剪刀布 (20)(20 分) 大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示: 现给出两人的交锋记录,请统计双方的胜.平.负次数,并且给出双方分别出什么手势的胜算 ...

  9. PAT 甲级 1011 World Cup Betting (20)(20 分)(水题,不用特别在乎精度)

    1011 World Cup Betting (20)(20 分) With the 2010 FIFA World Cup running, football fans the world over ...

  10. PTA 1005 Spell It Right (20)(20 分)水题

    1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...

随机推荐

  1. 20155234 2016-2017-2 《Java程序设计》第5周学习总结

    20155234 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 Java中所有错误都会被打包为对象,运用try.catch,可以在错误发生时显示友好的错误信 ...

  2. Java并发编程(3) JUC中的锁

    一 前言 前面已经说到JUC中的锁主要是基于AQS实现,而AQS(AQS的内部结构 .AQS的设计与实现)在前面已经简单介绍过了.今天记录下JUC包下的锁是怎么基于AQS上实现的 二 同步锁 同步锁不 ...

  3. 20145202马超 2016-2017-2 《Java程序设计》第三次实验

    实验三 敏捷开发与XP实践 http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的内容替换成IDEA 在IDEA中使用工具(Code->Re ...

  4. Android获取手机分辨率DisplayMetircs类

    关于Android中手机分辨率的使用 Android 可设置为随着窗口大小调整缩放比例,但即便如此,手机程序设计人员还是必须知道手机屏幕的边界,以避免缩放造成的布局变形问题. 手机的分辨率信息是手机的 ...

  5. Linux 查看内存插槽数、最大容量的方法

    查看内存插槽数: dmidecode|grep -P -A5 "Memory\s+Device"|grep Size|grep -v Range 查看最大容量: dmidecode ...

  6. LCD时序中设计到的VSPW/VBPD/VFPD/HSPW/HBPD/HFPD总结【转】

    转自:https://blog.csdn.net/u011603302/article/details/50732406 下面是我在网上摘录的一些关于LCD信号所需时钟的一些介绍, 描述方式一: 来自 ...

  7. Linux 多线程编程—使用条件变量实现循环打印

    编写一个程序,开启3个线程,这3个线程的ID分别为A.B.C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示:如:ABCABC….依次递推. 使用条件变量来实现: #inc ...

  8. 转载: Android开源库V - Layout:淘宝、天猫都在用的UI框架,赶紧用起来吧!

    阿里的UI库... 分析的很精辟... http://blog.csdn.net/carson_ho/article/details/71077193

  9. ksh函数

    在不同的shell环境里,shell脚本的写法是不同的 此链接为ksh环境的函数写法: https://blog.csdn.net/shangboerds/article/details/487115 ...

  10. 根据经纬度坐标计算距离-python

    一.两个坐标之间距离计算 参考链接: python实现 1.Python 根据地址获取经纬度及求距离 2.python利用地图两个点的经纬度计算两点间距离 LBS 球面距离公式 美团app筛选“离我最 ...