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. PHP mysqli_fetch_object() 函数

    定义和用法 mysqli_fetch_object() 函数从结果集中取得当前行,并作为对象返回. 注释:该函数返回的字段名是区分大小写的. <?php // 假定数据库用户名:root,密码: ...

  2. thinkphp6下载安装与配置图文详细讲解教程(composer下载安装)

    thinkphp6发布也有一段时间了,相对来说比较稳定,是时候学习一下thinkphp6框架,提前学习,到正式发布的时候,可以直接拿来做正式的项目,先人一步.thinkPHP6.0在5.1的基础上对底 ...

  3. AGC033D Complexity

    题意 给出一个\(n*m\)的\(0,1\)矩阵,若一个矩阵中的所有元素都相同,则这个矩阵的代价为\(0\),如果不是则选择一种将它分成两个子矩阵的方案,代价为所有方案中(两个子矩阵的代价的较大值+\ ...

  4. django基础教程(一)

    Django是一个开源的网站框架,mvc模式.提供了开发网站经常用的模块 优势:1.数据库 2.用正则匹配网址,传到对应的函数 3.后台 4.模板系统,与样式分开 5,缓存 Diango的组成:1.u ...

  5. python获取hive表时间格式最大分区

    #获取表的最大分区 import boto3 from datetime import datetime,timedelta def get_max_partition(db_name,table_n ...

  6. ueditor 图片选区错位问题,图片无法正常缩放

    当编辑框高度固定可内部滚动时,ueditor插入图片调节框显示bug 在使用百度euditor的编辑器时,我们常常需要让用户对插入的图片进行拉伸修改大小.当euditor的编辑框不随内容的增加而调节高 ...

  7. leetcode-hard-ListNode-148. Sort List

    mycode    97.37% 如果用上一个题目中”参考“的方法,res中放节点而不是val,就会超时 # Definition for singly-linked list. # class Li ...

  8. 深度学习变革视觉计算总结(CCF-GAIR)

    孙剑博士分享的是<深度学习变革视觉计算>,分别从视觉智能.计算机摄影学和AI计算三个方面去介绍. 他首先回顾了深度学习发展历史,深度学习发展到今天并不容易,过程中遇到了两个主要障碍: 第一 ...

  9. springboot内置分页技术

    1,在pom.xml中注入分页的配置 <dependency> <groupId>com.github.pagehelper</groupId> <artif ...

  10. nginx 反向代理实现负载均衡*配置实战

    重要点: 1配置反向代理多虚拟主机节点服务器 2经过反向代理后的节点服务器记录用户IP 3与反向代理配置相关的更多参数说明 4根据URL目录地址转发 (1)根据URL中的目录地址实现代理转发(动静分离 ...