PAT甲级——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 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
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
之前的题解定义了结构体,较为复杂:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
struct Users{
char num[20];
char pass[20];
bool flag = false;
}user[1005];
int main()
{
int N;
int sum=0;
scanf("%d",&N);
int i,j;
for(i=0;i<N;i++)
{
scanf("%s %s",user[i].num,user[i].pass);
for( j=0;j<strlen(user[i].pass);j++)
{
if(user[i].flag!=true)
{
if(user[i].pass[j]=='1') {user[i].pass[j]='@';user[i].flag=true;break;}
if(user[i].pass[j]=='0') {user[i].pass[j]='%';user[i].flag=true;break;}
if(user[i].pass[j]=='l') {user[i].pass[j]='L';user[i].flag=true;break;}
if(user[i].pass[j]=='O') {user[i].pass[j]='o';user[i].flag=true;break;}
}
if(user[i].flag==true)
{
sum++;
break;
}
}
}
if(sum)
{
printf("%d",sum);
for(int i=0;i<N;i++)
{
if(user[i].flag==true)
{
printf("\n");
printf("%s %s",user[i].num,user[i].pass);
}
}
}
else
{
if(N==1)
{
printf("There is 1 account and no account is modified");
}
else
{
printf("There are %d accounts and no account is modified",N);
}
}
}
更好的是:
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<string> v;
for(int i = 0; i < n; i++) {
string name, s;
cin >> name >> s;
int len = s.length(), flag = 0;
for(int j = 0; j < len; j++) {
switch(s[j]) {
case '1' : s[j] = '@'; flag = 1; break;
case '0' : s[j] = '%'; flag = 1; break;
case 'l' : s[j] = 'L'; flag = 1; break;
case 'O' : s[j] = 'o'; flag = 1; break;
}
}
if(flag) {
string temp = name + " " + s;
v.push_back(temp);
}
}
int cnt = v.size();
if(cnt != 0) {
printf("%d\n", cnt);
for(int i = 0; i < cnt; i++)
cout << v[i] << endl;
}
else if(n == 1) {
printf("There is 1 account and no account is modified");
}
else {
printf("There are %d accounts and no account is modified", n);
}
return 0;
}
使用C++里的vector,string组合将题目解出,省去了使用结构体的麻烦
PAT甲级——1035 Password (20分)的更多相关文章
- PAT 甲级 1035 Password (20 分)(简单题)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- PAT Advanced 1035 Password (20 分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642
PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)
1061 Dating (20 分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...
- 【PAT甲级】1035 Password (20 分)
题意: 输入一个正整数N(<=1000),接着输入N行数据,每行包括一个ID和一个密码,长度不超过10的字符串,如果有歧义字符就将其修改.输出修改过多少组密码并按输入顺序输出ID和修改后的密码, ...
- PAT (Advanced Level) Practice 1035 Password (20 分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- 【PAT】1035. Password (20)
题目:http://pat.zju.edu.cn/contests/pat-a-practise/1035 分析:简单题.直接搜索,然后替换,不会超时,但是应该有更好的办法. 题目描述: To pre ...
随机推荐
- 19 01 17 Django 模板 返回一个页面
模板 问题 如何向请求者返回一个漂亮的页面呢? 肯定需要用到html.css,如果想要更炫的效果还要加入js,问题来了,这么一堆字段串全都写到视图中,作为HttpResponse()的参数吗?这样定义 ...
- 【LeetCode】克隆图
[问题]给定无向连通图中一个节点的引用,返回该图的深拷贝(克隆).图中的每个节点都包含它的值 val(Int) 和其邻居的列表(list[Node]). 解释: 节点 的值是 ,它有两个邻居:节点 和 ...
- PHP循环语句练习题
<?php //输出0-100所有数字 for ($i=0; $i <101 ; $i++) { echo($i . '<br />'); }; //输出水仙花数 for ($ ...
- 线性数据结构案例1 —— 单向链表中获取倒数k个节点
一.介绍 先遍历整个链表获取链表长度length,然后通过 (length-index) 方式得到我们想要节点在链表中的位置. 二.代码 public Node findLastIndexNode( ...
- 翻译小工具制作,Python简单破解有道JS加密!
写这篇文章之前,我记得我以前好像公布一次.百度翻译的接口把版本号修改可以得到老版本,而老版本是没JS加密的,有道的呢也是一样的. ! 不过今天的教程不会这么low,咱们今天就老老实实把有道翻译的JS破 ...
- springboot-jar-web
预览 与springboot-jar的区别是: 1.pom.xml 将 <dependency> <groupId>org.springframework.boot</g ...
- vue项目配置多入口多出口【转载】
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/localhost_1314/article ...
- (递归)Hanoi Tower
#include<stdio.h>void move(int n,char a,char b){ printf("将第%d个盘子从%c移动到%c\n",n,a,b); ...
- Kettle无法下载以及点击无反应的问题
最开始用于解决MySQL转移数据到ORACLE的问题,尝试了几种方法. 1.直接从Mysql导出csv文件.这种方式最直接简单,但是问题是数据大的话,容易出现数据对不齐的情况,导入这个时候就会出现错误 ...
- mysql5.6免安装使用
一.去MYSQL官网下载MYSQL免安装版,由于我的系统是64位的,所以就下载了64位的Mysql版本 http://cdn.mysql.com//Downloads/MySQL-5.6/mysql- ...