教你夺冠


私信TA

用户名:835685327

访问量:148623

签 名:

相互交流 相互学习

等  级
排  名 13
经  验 21608
参赛次数 0
文章发表 84
年  龄 0
在职情况 学生
学  校 辣鸡施工大学
专  业

  自我简介:

努力刷题 熟能生巧!

参考代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
	int M;
	scanf("%d", &M);
	
	int res[M];    //存放结果的数组 
	int index = 0; //数组下标
	
	char str[50];
	int i;
	for(i = 0; i < M; i++)
	{
		scanf("%s", str); 
		int len = strlen(str);
		
		if (len < 8 || len > 16)
		{
			res[index++] = 0;
		}
		else
		{
			int hasup  = 0;
			int haslow = 0;
			int hasnum = 0;
			int hasoth = 0;
			int j;
			for (j = 0; j < len; j++)
			{
				if (isupper(str[j]))
					hasup = 1;
				else if (islower(str[j]))
					haslow = 1;
				else if (isdigit(str[j]))
					hasnum = 1;
				else if (str[j] == '~' || str[j] == '!' || str[j] == '@' || str[j] == '#' || str[j] == '$' || str[j] == '%' || str[j] == '^')
					hasoth = 1;
			}
			
			//判断四类字符至少有三类,只要三个标志位总和大于等于3即可
			int hassum = hasup + haslow + hasnum + hasoth;
			if (hassum >= 3)
				res[index++] = 1;
			else
				res[index++] = 0;
		}	
		
		memset(str, 0, 50); //清空数组
	}
	
	//输出结果
	int k;
	for (k = 0; k < index; k++)
	{
		if (res[k] == 1)
			printf("YES\n");
		else
			printf("NO\n");
	}
	
	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区