Password
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 23180 Accepted Submission (s): 9260
Problem Description
There is a saying on the Internet: "I often go online. How can I leave it alone ~ ". In fact, it is not difficult to learn security knowledge to access the Internet with peace of mind.
First, we need to set a secure password. What kind of password is secure? Generally, a secure password must meet at least the following two conditions:
(1). The password length must be greater than or equal to 8 and cannot exceed 16.
(2) The characters in the password should come from at least three of the four groups in the following "character category.
The four character categories are:
1. uppercase letters: A, B, C... Z;
2. lowercase letters: a, B, c... z;
3. Number: 0, 1, 2... 9;
4. Special symbols :~,!, @, #, $, %, ^;
Give you a password. Your task is to determine whether it is a secure password.
Input
The first line of the input data contains a number of M, followed by M rows, 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
Import java. io. bufferedInputStream; import java. util. *; import java. util. regex. matcher; import java. util. regex. pattern; public class Main {public static void main (String [] args) {vertex SC = new vertex (new BufferedInputStream (System. in); int n = SC. nextInt (); SC. nextLine (); for (int I = 0; I <n; I ++) {String s = SC. nextLine (); if (s. length ()> = 8 & s. length () <= 16) {// match an uppercase letter A-Z any letter Pattern p1 = Pa Ttern. compile ("[A-Z]"); Matcher m1 = p1.matcher (s); // match lowercase letters a-z any one letter Pattern p2 = Pattern. compile ("[a-z]"); Matcher m2 = p2.matcher (s); // match any 0-9 digit Pattern p3 = Pattern. compile ("\ d"); Matcher m3 = p3.matcher (s); // match the special character Pattern p4 = Pattern. compile ("~ |! | @ | # | \\$ | % | \\^ "); Matcher m4 = p4.matcher (s); if (m1.find () & m2.find () & m3.find () & m4.find () {System. out. println ("YES");} else if (m1.find () & m2.find () & m3.find () {System. out. println ("YES");} else if (m1.find () & m2.find () & m4.find () {System. out. println ("YES");} else if (m1.find () & m3.find () & m4.find () {System. out. println ("YES");} else if (m2.find () & m3.find () & m4.find () {System. out. println ("YES");} elseSystem. out. println ("NO");} elseSystem. out. println ("NO ");}}}