题目不难,就是内容有点多
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String pw = in.nextLine();
int length = pw.length();
int lengthScore;
// 长度判断
if (length >= 8) {
lengthScore = 25;
} else if (length >= 5) {
lengthScore = 10;
} else {
lengthScore = 5;
}
boolean lowercase = false, uppercase = false;
int symbolCnt = 0, digitCnt = 0;
// 元素
for (int i = 0; i < length; i++) {
char ch = pw.charAt(i);
if(ch >= 'a' && ch <= 'z') lowercase = true;
if(ch >= 'A' && ch <= 'Z') uppercase = true;
if(ch >= '0' && ch <= '9') digitCnt++;
if((ch >= '!' && ch <= '/') || (ch >= ':' && ch <= '@')
|| (ch >= '[' && ch <= '`') || (ch >= '{' && ch <= '~')) symbolCnt++;
}
// 含有数字:0表示没有,10表示包含1个数字,20表示有2个及以上的数字
int haveDigit = digitCnt == 0 ? 0 : (digitCnt == 1 ? 10 : 20);
// 含有字母:0表示没有,10表示仅包含大写或小写字母,20表示大小写混合
int haveLetter = lowercase && uppercase ? 20 : (lowercase || uppercase ? 10 : 0);
// 含有符号:0表示没有,10表示包含1个符号,25表示有2个及以上的符号
int haveSymbol = symbolCnt == 0 ? 0 : (symbolCnt == 1 ? 10 : 25);
// 奖励:0表示没有,2分(字母和数字),3分(字母、数字和符号),5分(字母大小写、数字和符号)
int award = 0;
if (haveLetter == 20 && haveDigit > 0 && haveSymbol > 0) {
award = 5;
} else if (haveLetter == 10 && haveDigit > 0 && haveSymbol > 0) {
award = 3;
} else if (haveLetter == 0 && haveDigit > 0 && haveSymbol > 0) {
award = 2;
}
int score = lengthScore + haveLetter + haveDigit + haveSymbol + award;
String result;
if (score >= 90) {
result = "VERY_SECURE";
} else if (score >= 80) {
result = "SECURE";
} else if (score >= 70) {
result = "VERY_STRONG";
} else if (score >= 60) {
result = "STRONG";
} else if (score >= 50) {
result = "AVERAGE";
} else if (score >= 25) {
result = "WEAK";
} else {
result = "VERY_WEAK";
}
System.out.println(result);
}
}

京公网安备 11010502036488号