题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); scanner.useDelimiter("\n"); while (scanner.hasNext()) { String S = scanner.next(); int A = 0; int a = 0; int number = 0; int symbol = 0; int sum = S.length()<=4?5:S.length()>=8?25:10; for (int i = 0; i < S.length(); i++) { if (S.charAt(i) >= 'A' && S.charAt(i) <= 'Z' && (A&1)==0) { A = 1; } else if (S.charAt(i) >= 'a' && S.charAt(i) <= 'z' && (a&1)==0) { a = 1; } else if (S.charAt(i) >= '0' && S.charAt(i) <= '9' && number <= 2) { number++; } else if (symbol <= 2 && S.charAt(i) >= 0x21 && S.charAt(i) <= 0x2F || S.charAt(i) >= 0x3A && S.charAt(i) <= 0x40 || S.charAt(i) >= 0x5B && S.charAt(i) <= 0x60||S.charAt(i) >= 0x7B && S.charAt(i) <= 0x7E) { symbol++; } } //字母 if (A>0&&a>0) { sum+=20; } else if (A>0||a>0) { sum+=10; } if (number>1) { sum+=20; } else if (number==1) { sum+=10; } if (symbol>1) { sum+=25; } else if (symbol==1){ sum+=10; } if (A>0&&a>0&&symbol>0&&number>0){ sum+=5; }else if (number>0&&symbol>0&&(A>0||a>0)){ sum+=3; } else if ((A>0||a>0)&&number>0){ sum+=2; } if (sum>=90) { System.out.println("VERY_SECURE"); } else if (sum>=80){ System.out.println("SECURE"); } else if (sum>=70){ System.out.println("VERY_STRONG"); } else if (sum>=60){ System.out.println("STRONG"); } else if (sum>=50){ System.out.println("AVERAGE"); } else if (sum>=25){ System.out.println("WEAK"); } else { System.out.println("VERY_WEAK"); } } } }