HDU 2043 密碼

來源:互聯網
上載者:User
密碼

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 23180 Accepted Submission(s): 9260

Problem Description網上流傳一句話:"常在網上飄啊,哪能不挨刀啊~"。其實要想能安安心心地上網其實也不難,學點安全知識就可以。

首先,我們就要設定一個安全的密碼。那什麼樣的密碼才叫安全的呢?一般來說一個比較安全的密碼至少應該滿足下面兩個條件:

(1).密碼長度大於等於8,且不要超過16。
(2).密碼中的字元應該來自下面“字元類別”中四組中的至少三組。

這四個字元類別分別為:
1.大寫字母:A,B,C...Z;
2.小寫字母:a,b,c...z;
3.數字:0,1,2...9;
4.特殊符號:~,!,@,#,$,%,^;

給你一個密碼,你的任務就是判斷它是不是一個安全的密碼。

Input輸入資料第一行包含一個數M,接下有M行,每行一個密碼(長度最大可能為50),密碼僅包括上面的四類字元。

Output對於每個測試執行個體,判斷這個密碼是不是一個安全的密碼,是的話輸出YES,否則輸出NO。

Sample Input

3a1b2c3d4Linle@ACM^~^@^@!%

Sample Output

NOYESNO
  
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) {Scanner sc = new Scanner(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) {//匹配 大寫字母 A-Z任意一個字母Pattern p1 = Pattern.compile("[A-Z]");Matcher m1 = p1.matcher(s);//匹配小寫字母a-z任意一個字母Pattern p2 = Pattern.compile("[a-z]");Matcher m2 = p2.matcher(s);//匹配0-9任意一個數字Pattern p3 = Pattern.compile("\\d");Matcher m3 = p3.matcher(s);//匹配特殊字元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");}}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.