PTA (Advanced Level)1035.Password
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的更多相关文章
- PAT (Advanced Level) 1035. Password (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- 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 ...
- PTA (Advanced Level) 1004 Counting Leaves
Counting Leaves A family hierarchy is usually presented by a pedigree tree. Your job is to count tho ...
- PTA (Advanced Level) 1020 Tree Traversals
Tree Traversals Suppose that all the keys in a binary tree are distinct positive integers. Given the ...
- PTA (Advanced Level) 1010 Radix
Radix Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? ...
- PTA(Advanced Level)1025.PAT Ranking
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- 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 ...
- PTA (Advanced Level) 1008 Elevator
Elevator The highest building in our city has only one elevator. A request list is made up with Npos ...
- PTA (Advanced Level) 1007 Maximum Subsequence Sum
Maximum Subsequence Sum Given a sequence of K integers { N1, N2, ..., NK }. A continuous su ...
随机推荐
- Error: 'The service did not respond in a timely fashion'
Windows启动时候报这个错,不应在OnStart放执行长的过程,需要开另一个线程来做才能顺利启动 Windows Services: OnStart loop - do I need to del ...
- 多线程中volatile关键字的作用
原文链接:https://blog.csdn.net/xuwentao37x/article/details/27804169 多线程的程序是出了名的难编写.难验证.难调试.难维护,这通常是件苦差事. ...
- word标题前出现黑块解决方案
1,将光标定位到出现问题的标题前面 2,点击最上方的标题,然后点击修改-->格式-->编号-->无-->确定. 3,重新设置标题即可.
- Python 通过文件名批量移动文件
Python 通过文件名批量移动文件 https://stackoverflow.com/questions/28913088/moving-files-with-wildcards-in-pytho ...
- cropbox.js 头像裁剪插件
cropbox.js 一个轻量级和简单的JavaScript,Jquery,YUI插件来裁剪您的头像. 特征 支持dataUrl显示图像(函数getDataURL) 支持Blob上传图片(函数getB ...
- WM_PAINT(父子窗口间)
WM_PAINT(父子窗口间) 窗口句柄(HWND)都是由操作系统内核管理的,系统内部有一个z-order序列,记录着当前从屏幕底部(假象的从屏幕到眼睛的方向),到屏幕最高层的一个窗口句柄的排序,这个 ...
- Java基础_线程的使用及创建线程的三种方法
线程:线程是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行执行不同的任务. 进程:进 ...
- response 下载文件火狐浏览器文件名乱码问题
string path = Server.MapPath(Url.Content("~/") + "UploadFiles/Template/"); ...
- springboot多个数据源
1.启动两个mysql,可以按照如下操作使用docker来部署mysql容器,比较简单 https://www.cnblogs.com/qq931399960/p/11527222.html 2.如果 ...
- 影响mysql性能的因素
一.服务器硬件. CPU不够快,内存不够多,磁盘IO太慢. 对于计算密集型的应用,CPU越可能去影响系统的性能,此时,CPU和内存将越成为系统的瓶颈. 当热数据大小远远超过系统可用内存大小时,IO资源 ...