Hangzhou Electric Oj brush title (2043)

password

Subject description:

Circulated on the Internet saying: "Often floating in the Internet, ah, how can I not the knife ah ~." In fact, in order to be able to actually satisfied staying online is not difficult, you can learn some safety knowledge.

First, we must set up a secure password. What kind of password called safe? Generally a more secure password should meet at least the following two conditions:

(1) greater than the length of the password is equal to 8, and not more than 16.
(2) The password characters should come from below "character class" in at least three of the four groups.

The four character categories are:
1. capital letters: A, B, C ... the Z;
2. lowercase letters: A, B, C ... Z;
3. Digital: 0,1,2 ... 9;
4 special characters: ~,!, @, #, $,%, ^;

give you a password, your task is to determine if it is a secure password.

Input

The first line of input data comprises a number M, took M rows, each row a password (maximum possible length of 50), including only the above four categories of code characters.

Output

For each test case to determine the password is not a secure password is then output YES, otherwise output NO.

Sample Input

3 
a1b2c3d4 
Linle ACM @ 
^ ~ ^ @ ^ @!%

Sample Output

NO 
YES 
NO

By the answer:

#include <stdio.h>         
#include<string.h>
int main(){
	int m,i,len,flag1,flag2,flag3,flag4;
	char a[50];
	while(scanf("%d",&m)!=EOF){
	    while(m--){ 
	        flag1=flag2=flag3=flag4=0;
	    	scanf("%s",&a);                //输入字符串 
	    	len=strlen(a);
	    	if(len<8||len>16){             //长度限制 
	    		printf("NO\n");
	    		continue;
			}
			for(i=0;a[i]!='\0';i++){        //遍历数组 
			    if(a[i]>='A'&&a[i]<='Z'){flag1=1;}           //只要有一个元素为大写字母,则flag置为1 
				else if(a[i]>='a'&&a[i]<='z'){flag2=1;}	
			    else if(a[i]>='0'&&a[i]<='9'){flag3=1;}
				else if(a[i]=='~'||a[i]=='!'||a[i]=='@'||a[i]=='#'||a[i]=='$'||a[i]=='%'||a[i]=='^'){flag4=1;}
			}
			if((flag1+flag2+flag3+flag4)>=3){               //密码中的字符应该来自以上“字符类别”中四组中的至少三组。
					printf("YES\n");
			}else{
					printf("NO\n");
			}
			
		}
    }
    return 0;
}

 

Published 55 original articles · won praise 0 · Views 997

Guess you like

Origin blog.csdn.net/ZhangShaoYan111/article/details/104227737