Password - primary

【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

【Code】

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner reader = new Scanner(System.in);
        int n = reader.nextInt();
        String s[] = new String[n];
        for(int i=0;i<n;i++){
            s[i]=reader.next();
        }
        
        for(int i=0;i<n;i++){
            int daxie = 0;
            int xiaoxie = 0;
            int shuzi = 0;
            int fuhao = 0;
            if(s[i].length()>=8&&s[i].length()<=16){
                for(int j=0;j<s[i].length();j++){
                    if(s[i].charAt(j)>=65&&s[i].charAt(j)<=90)
                        daxie++;
                    else if(s[i].charAt(j)>=97&&s[i].charAt(j)<=122)
                        xiaoxie++;
                    else if(s[i].charAt(i)>=48&&s[i].charAt(j)<=57)
                        shuzi++;
                    else fuhao++;
                }
                if(daxie>0&&xiaoxie>0&&shuzi>0||daxie>0&&xiaoxie>0&&fuhao>0||daxie>0&&shuzi>0&&fuhao>0||xiaoxie>0&&shuzi>0&&fuhao>0){
                    System.out.println("YES");
                }else{
                    System.out.println("NO");
                }
            }else{
                System.out.println("NO");
            }
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/IcyYs/p/11446374.html