Hangdian oj2043 password

Problem Description

There is a saying circulating on the Internet: "I often float on the Internet, how can I not get a knife~". In fact, it is not difficult to be able to surf the Internet at ease, as long as you learn some security knowledge.

First, we need to set a secure password. So what kind of password is safe? Generally speaking, a relatively secure password should meet at least the following two conditions:

(1). The password length is greater than or equal to 8, and should not exceed 16.
(2). The characters in the password should be from at least three of the four groups in the "Character Category" below.

The four character categories are:
1. Uppercase letters: A,B,C...Z;
2.Lowercase letters: a,b,c...z;
3.Numbers: 0,1,2... 9;
4. Special symbols: ~,!,@,#,$,%,^;

give you a password, your task is to judge whether it is a safe password.

 

Input
The first line of the input data contains a number M, followed by M lines, each line has a password (the maximum length may be 50), and the password only includes the above four types of characters.

 

Output
For each test instance, determine whether the password is a secure password, if yes, output YES, otherwise output NO.

 

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

 

Sample Output
NO YES NO
 
This question is about character statistical processing of strings, and I found that there are no traps, but the pass rate is less than 50%.
1 #include<iostream>
 2 #include<cstring>
 3  using  namespace std;
 4  int main()
 5  {
 6      int n,len,count[ 5 ],c;
 7      char s[ 50 ];
 8      while (cin>> n)
 9      {        
 10          cin.get (); // Must add, read carriage return, otherwise the following cin.getline () will read empty lines and be blocked 11 while (n-- )
 12         {
 13              c = 0 ; //
          Initialize 
14              memset(count, 0 , sizeof ( int )* 5 ); // memset initializes 15 by the number of bytes (third parameter)
              memset(s, ' \0 ' , 50 );
 16              cin.getline(s, 50 );
 17              len = strlen(s);    
 18 if (len< 8 ||len> 16 ) // length does not match 19             {
 20                  cout<< " NO " << endl;
             
 21                 continue;
22             }
23             for(int i=0;i<len;i++)
24             {
25                 if(s[i]>='A'&&s[i]<='Z')    count[0]++;//字符为A~Z计数 
26                 else if(s[i]>='a'&&s[i]<='z')    count[1]++; 
27                 else if(s[i]>='0'&&s[i]<='9')    count[2]++; 
28                 else if(s[i]=='~'||s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]=='$'||s[i]=='%'||s[i]=='^')    count[3]++;
29                 else    count[4]++;        30Other characters count        //
             }
31             if(count[4])//有其它字符不符合 
32             {
33                 cout<<"NO"<<endl;
34             }
35             else
36             {
37                 for(int i=0;i<4;i++)
38                     if(count[i])    c++;
39                 if(c<3)        cout<<"NO"<<endl;
40                 else    cout<<"YES"<<endl;
41 
42             }
43         }    
44     } 
45     return 0;
46 }

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324798180&siteId=291194637