Password(PAT)

1.题目描述

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.
为了为PAT做准备,法官有时必须为用户生成随机密码。问题是总是有一些令人困惑的密码,因为很难区分1(1)和l(小写的L),或0(0)和O(大写的o)。一种解决方案是将1(1)替换为@,0替换为%,l替换为L,O替换为o。现在,您的工作是编写一个程序来检查法官生成的帐户,并帮助用户修改混淆的密码。

2.输入描述:

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.
每个输入文件包含一个测试用例。每一种情况都包含一个正整数N(<=1000),后面是N行帐户。每个帐户由用户名和密码组成,它们都是不超过10个字符的字符串,没有空格。

3.输出描述:

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.
对于每个测试用例,首先打印已修改的帐户号M,然后在以下M行中打印修改后的帐户信息,即用户名和相应的修改密码。这些帐户必须按照读入的顺序打印。如果没有修改帐户,在一行中打印“There are N accounts and no account is modified”,其中N是帐户的总数。然而,如果N是一个,你必须打印“There is 1 account and no account is modified”代替。

4.输入例子:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

5.输出例子:

2
Team000002 RLsp%dfa
Team000001 R@spodfa

6.源代码:

#include<stdio.h>
#include<stdlib.h>
typedef struct
{
	int flag; //表示修改状态
	char User[11];
	char Pwd[11];
}Account;

int main()
{
	int N;
	scanf("%d", &N);
	
	Account *A;
	A=(Account *)malloc(N * sizeof(Account));

	int i, j,count=0;
	for(i = 0; i < N; i++)
	{
		scanf("%s %s", A[i].User, A[i].Pwd);

		A[i].flag = 0;//默认所有账户未被修改的状态

		for(j = 0; A[i].Pwd[j] != '\0'; j++)//遍历密码
		{
			switch(A[i].Pwd[j])//修改相应字符并记录修改状态
			{
				case '0':A[i].Pwd[j] = '%';A[i].flag=1;break;
				case '1':A[i].Pwd[j] = '@';A[i].flag=1;break;
				case 'l':A[i].Pwd[j] = 'L';A[i].flag=1;break;
				case 'O':A[i].Pwd[j] = 'o';A[i].flag=1;break;
				default:break;
			}
			
		}

		if(A[i].flag == 1)//计数修改的账户数量
				count++;
	}

	if(count != 0)//输出被修改的账户数和账户信息
	{
		printf("%d\n", count);
		for(i = 0; i < N; i++)
		{
			if(A[i].flag == 1)
				printf("%s %s\n", A[i].User, A[i].Pwd);
		}
	}
	else	//特殊情况的判断
		if(N == 1)
			printf("There is 1 account and no account is modified\n");		
		else
			printf("There are %d accounts and no account is modified\n", N);		
	return 0;
}
全部评论

相关推荐

真是做吐了🤮
投递美团等公司10个岗位 >
点赞 评论 收藏
分享
03-10 21:11
武汉大学 运营
学不懂的那种:先天考公圣体
点赞 评论 收藏
分享
如题,鼠鼠快碎掉了。鼠鼠正在投暑期和日常的实习,可能是因为简历太差吧,好多初筛都没有过,所以其实格外珍惜每一次的约面。尤其鼠鼠是八股选手,但凡碰到喜欢问项目的面试官是直接速通鼠掉。那是一个万里无云的晚上,鼠鼠接到tx某子公司的约面,虽然没算法题但是问得我汗流浃背,面试官从我的八股批判到我的项目继而批判到我的实习,感觉基本上除了八股这种特定答案之外每一个问题都要质问我,尤其是询问到实习的时候我解释完之后直接来了一句“那你实习也啥也没做啊”,鼠鼠直接原地碎掉。之后的问题鼠鼠也不太记得了,大部分都是直接吟诵咒语,肌肉记忆直接不过脑子。因为接二连三的压力鼠鼠直接摆烂了,回答的时候也不太看屏幕直接开始搓...
机器人为什么是猫呀:楼主要自信。好的面试官是会照顾面试者情绪的,不会直接说那么伤人的话。面试表现其实很看自己的心态跟情绪,这些又和面试官的反馈很相关。而且有些面试官很高傲,不求甚解,自认为你的东西看一眼很简单,就不会听你说了,却没有从一个没有丰富工作经验的人的角度去思考。楼主不要因为这些影响心态,不要怀疑自己,只要遇到一个“合适”的面试官就会好很多的。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务