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
思路
  • 用结构体表示数据,如果密码需要修改的就放到结构体数组里,最后根据修改的数量和n的大小来决定输出
代码
#include<bits/stdc++.h>
using namespace std;
struct user
{
string id;
string password;
}a[1010];
int a_num = 0;
int main()
{
int n;
cin >> n;
string id, ps;
bool modify = false;
for(int j=0;j<n;j++)
{
cin >> id >> ps;
modify = false; //表示有无修改过
for(int i=0;i<ps.size();i++)
{
if(ps[i] == '1')
{
modify = true;
ps[i] = '@';
}else
if(ps[i] == '0')
{
modify = true;
ps[i] = '%';
}else
if(ps[i] == 'l')
{
modify = true;
ps[i] = 'L';
}else
if(ps[i] == 'O')
{
modify = true;
ps[i] = 'o';
}
}
if(modify)
{
a[a_num].id = id;
a[a_num++].password = ps;
}
}
if(a_num == 0)
if(n != 1)
printf("There are %d accounts and no account is modified", n);
else
printf("There is 1 account and no account is modified");
else
{
cout << a_num<< endl;
for(int i=0;i<a_num;i++)
{
cout << a[i].id << " " << a[i].password;
cout << endl;
}
}
return 0;
}
引用

https://pintia.cn/problem-sets/994805342720868352/problems/994805454989803520

PTA (Advanced Level)1035.Password的更多相关文章

  1. PAT (Advanced Level) 1035. Password (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  2. PTA(Advanced Level)1036.Boys vs Girls

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  3. PTA (Advanced Level) 1004 Counting Leaves

    Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...

  4. PTA (Advanced Level) 1020 Tree Traversals

    Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Given the ...

  5. PTA (Advanced Level) 1010 Radix

    Radix Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? ...

  6. PTA(Advanced Level)1025.PAT Ranking

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  7. PTA (Advanced Level) 1009 Product of Polynomials

    1009 Product of Polynomials This time, you are supposed to find A×B where A and B are two polynomial ...

  8. PTA (Advanced Level) 1008 Elevator

    Elevator The highest building in our city has only one elevator. A request list is made up with Npos ...

  9. PTA (Advanced Level) 1007 Maximum Subsequence Sum

    Maximum Subsequence Sum Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous su ...

随机推荐

  1. org.apache.commons.io.FilenameUtils 常用的方法

    /** * getExtension * 获取文件的后缀名 */ public static void testGetExtension() { String extension = Filename ...

  2. [Luogu] 魔法树

    https://www.luogu.org/problemnew/show/P3833 树链剖分 + 线段树 为啥会RE?? 不解 #include <iostream> #include ...

  3. 栈的数组和链表实现(Java实现)

    我以前用JavaScript写过栈和队列,这里初学Java,于是想来实现栈,基于数组和链表. 下面上代码: import java.io.*; //用接口来存放需要的所有操作 interface st ...

  4. Jmeter在一次进程中如何循环执行某个步骤

    在使用Jmeret工具过程中比如我使用借款功能,如果想多借几次就需要一次次执行脚本,如果我在脚本执行过程中登陆一次,可以重复执行借款这一个操作那么就方便多了 于是就用到(循环控制器)这个功能 1.我需 ...

  5. 转载:在Excel中将数据库字段转换成驼峰式

    转载地址 在Excel中将数据库字段转换成驼峰式 1.将数据库字段复制到Excel表格第一列: 2.在第二列顶部输入=PROPER(A1)命令: 3.在第三列顶部输入=SUBSTITUTE(B1,&q ...

  6. vue 动态渲染数据很慢或不渲染

    vue 动态渲染数据很慢或不渲染 原因是因为vue检测速度很慢,因为多层循环了,在VUE 2.x的时候还能渲染出来,1.x的时候压根渲染不出来.解决方式:在动态改变数据的方法,第一行加上 this.$ ...

  7. LC 971. Flip Binary Tree To Match Preorder Traversal

    Given a binary tree with N nodes, each node has a different value from {1, ..., N}. A node in this b ...

  8. jQuery显示隐藏div的几种方法

    1.$("#demo").attr("style","display:none;");//隐藏div $("#demo" ...

  9. Ubuntu16.04中VirtualBox中安装FreeBSD

    获取镜像 FreeBSD官网:https://www.freebsd.org,打开后即可看到“Download Freebsd”的按钮,点击进去 进入版本选择的页面.可以看到当前RELEASR版本,旧 ...

  10. Linux文档中翻页和搜索关键字

    按键 进行工作空格键 向下翻一页[Page Down] 向下翻一页[Page Up] 向上翻一页[Ctrl + U] 向上翻一页[Ctrl + D] 向下翻一页/string 向下搜寻string这个 ...