PAT(A) - 1035. Password (20)
来源:互联网 发布:安装sql server 2008 编辑:程序博客网 时间:2024/05/24 22:44
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:
3Team000002 Rlsp0dfaTeam000003 perfectpwdTeam000001 R1spOdfaSample Output 1:
2Team000002 RLsp%dfaTeam000001 R@spodfaSample Input 2:
1team110 abcdefg332Sample Output 2:
There is 1 account and no account is modifiedSample Input 3:
2team110 abcdefg222team220 abcdefg333Sample Output 3:
There are 2 accounts and no account is modified
没什么难度,AC代码:
#include <cstdio>#include <string.h>#define N 1010typedef struct { char ID[11]; char password[11];} Stu;Stu stu[N];int result[N] = { 0 };bool Judge( char str[] ) { int len = strlen( str ); bool flag = false; for( int i = 0; i < len; i++ ) { if( str[i] == '0' ) { str[i] = '%'; flag = true; } if( str[i] == 'l' ) { str[i] = 'L'; flag = true; } if( str[i] == '1' ) { str[i] = '@'; flag = true; } if( str[i] == 'O' ) { str[i] = 'o'; flag = true; } } return flag;}int main() { //freopen( "123.txt", "r", stdin ); int n; char id[15], key[15]; scanf( "%d", &n ); int count = 0; for( int i = 0; i < n; i++ ) { scanf( "%s %s", stu[i].ID, stu[i].password ); bool flag = Judge( stu[i].password ); if( flag ) { result[count] = i; count++; } } if( count == 0 && n != 1 ) { printf( "There are %d accounts and no account is modified", n ); return 0; } else if( count == 0 && n == 1 ) { printf( "There is 1 account and no account is modified" ); return 0; } printf( "%d\n", count ); for( int i = 0; i < count; i++ ) { int index = result[i]; printf( "%s %s\n", stu[index].ID, stu[index].password ); } return 0;}
- PAT A 1035. Password (20)
- PAT(A) - 1035. Password (20)
- PAT-A 1035. Password (20)
- PAT-A-1035. Password (20)
- PAT-A 1035. Password
- 【PAT】1035. Password (20)
- 1035. Password (20)-PAT
- PAT 1035. Password (20)
- pat 1035. Password (20)
- PAT 1035. Password (20)
- PAT 1035. Password (20)
- PAT 1035. Password (20)
- PAT (Advanced) 1035. Password (20)
- PAT甲级.1035. Password (20)
- 【PAT甲级】1035. Password (20)
- 1035. Password (20)PAT 甲级
- PAT甲级1035. Password (20)
- PAT 1035 1035. Password (20)
- Shell 命令的语法
- 【Java并发编程】之九:死锁(含代码)
- Spring 4.x 中使用注解 @ResponseBody 返回json数据的配置
- hdu 1698 区间更新
- 【Java并发编程】之十:使用wait/notify/notifyAll实现线程间通信的几点重要说明
- PAT(A) - 1035. Password (20)
- 例题:回文词(UVa401)
- 【Java并发编程】之十一:线程间通信中notify通知的遗漏(含代码)
- HDU 5492 Find a path
- 【Java并发编程】之十二:线程间通信中notifyAll造成的早期通知问题(含代码)
- 用户行为分析笔记(二):系统的整体架构
- Android 属性大全
- Android 布局参数对象LayoutParam的使用
- 重写Spring的PropertyPlaceholderConfigurer,从数据库加载配置数据