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;
}
全部评论

相关推荐

02-14 15:34
门头沟学院 Java
Java抽象带篮子:专业技能怎么写可以看看我发的帖子
点赞 评论 收藏
分享
会飞的猿:我看你想进大厂,我给你总结一下学习路线吧,java语言方面常规八股要熟,那些java的集合,重点背hashmap八股吧,jvm类加载机制,运行时分区,垃圾回收算法,垃圾回收器CMS、G1这些,各种乐观锁悲观锁,线程安全,threadlocal这些。在进阶一些的比如jvm参数,内存溢出泄漏排查,jvm调优。我这里说的只是冰山一角,详细八股可以去网上找,这不用去买,都免费资源。mysql、redis可以去看小林coding,我看你简历上写了,你一定要熟,什么底层b+树、索引结构、innodb、mvcc、undo log、redo log、行级锁表级锁,这些东西高频出现,如果面试官问我这些我都能笑出来。消息队列rabbitmq也好kafka也好,学一种就行,什么分区啊副本啊确认机制啊怎么保证不重复消费、怎么保证消息不丢失这些基本的一定要会,进阶一点的比如LEO、高水位线、kafka和rocketmq底层零拷贝的区别等等。计算机网络和操作系统既然你是科班应该理解起来问题不大,去看小林coding这两块吧,深度够了。spring boot的八股好好看看吧,一般字节腾讯不这么问,其他的java大厂挺爱问的,什么循环依赖啥的去网上看看。数据结构的话科班应该问题不大,多去力扣集中突击刷题吧。项目的话其实说白了还是结合八股来,想一想你写的这些技术会给你挖什么坑。除此之外,还有场景题、rpc、设计模式、linux命令、ddd等。不会的就别往简历上写了,虽然技术栈很多的话好看些,但背起来确实累。总结一下,多去实习吧,多跳槽,直到跳到一个不错的中厂做跳板,这是一条可行的进大厂的路线。另外,只想找个小厂的工作的话,没必要全都照这些准备,太累了,重点放在框架的使用和一些基础八股吧。大致路线就这样,没啥太多难度,就是量大,你能达到什么高度取决于你对自己多狠,祝好。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务