您的位置:首页 > 其它

1035. Password (20)

2018-02-22 18:23 197 查看
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
题目大意:
为了准备PAT,管理员有时必须为用户产生随机密码。问题是因为很难区分1(1)与l(小写的l),或者0(0)(大写的O)。一个解决方案是用@替换1,用%替换0,用L替换l,用o替换O。现在,你的任务是编写一个程序来检查管理员生成的账户,并帮助管理员修改容易混淆的密码。
输入规格:
每个输入文件包含一个测试用例。每个测试用例包含一个正整数N(<=1000),然后是N行账户。每个账户包含一个用户名和密码,他们都是不超过10个字符且不包含空格的字符串。
输出规格:
对于每个测试用例,首先打印被修改的账户的数量M,接下来在下面的M行中打印修改后的账户信息,即用户名和相应的修改后的密码。这些账户的信息必须按读入的顺序打印。如果没有账户被修改,在一行中打印“有N个账户,没有账户被修改”,其中N是账户的总数。但是,如果N是1,你必须打印“有一个账户,没有账户被修改”。

代码:#include<stdio.h>
#include<string.h>
struct node
{
char username[15];
char userpassword[15];
}user[1001];
int main()
{
int i,j,n,m,k,t,l=0,flag;
char name[15],password[15];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s %s",name,password);
flag=0;
for(j=0;j<strlen(password);j++)
{
if(password[j]=='1')
{
password[j]='@';
flag=1;
}
else if(password[j]=='0')
{
password[j]='%';
flag=1;
}
else if(password[j]=='l')
{
password[j]='L';
flag=1;
}
else if(password[j]=='O')
{
password[j]='o';
flag=1;
}

}
if(flag==1)
{
strcpy(user[l].username,name);
strcpy(user[l].userpassword,password);
l++;
}

}
if(l==0)
{
if(n==1)
printf("There is %d account and no account is modified\n",n);
else
printf("There are %d accounts and no account is modified\n",n);
}
else
{
printf("%d\n",l);
for(i=0;i<l;i++)
{
printf("%s %s\n",user[i].username,user[i].userpassword);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: