1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
public class HJ087 {
public static String[] grades = {"VERY_SECURE", "SECURE", "VERY_STRONG", "STRONG", "AVERAGE", "WEAK", "VERY_WEAK"};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(getPwdSecurityGrade(sc.nextLine()));
}
public static String getPwdSecurityGrade(String pwd) {
int score = 0;
int n = pwd.length();
if (n <= 4) {
score += 5;
} else if (n >= 5 && n <= 7) {
score += 10;
} else {
score += 25;
}
boolean upperFlag = false;
boolean lowerFlag = false;
int numCnt = 0;
int symbolCnt = 0;
for (char c : pwd.toCharArray()) {
if (c >= 'a' && c <= 'z') {
upperFlag = true;
} else if (c >= 'A' && c <= 'Z') {
lowerFlag = true;
} else if (c >= '0' && c <= '9') {
numCnt++;
} else {
symbolCnt++;
}
}
if (upperFlag && lowerFlag) {
score += 20;
} else if (upperFlag || lowerFlag) {
score += 10;
}
if (numCnt == 1) {
score += 10;
} else if (numCnt > 1) {
score += 20;
}
if (symbolCnt == 1) {
score += 10;
} else if (symbolCnt > 1) {
score += 25;
}
if (upperFlag && lowerFlag && numCnt > 0 && symbolCnt > 0) {
score += 5;
} else if ((upperFlag || lowerFlag) && numCnt > 0 && symbolCnt > 0) {
score += 3;
} else if ((upperFlag || lowerFlag) && numCnt > 0) {
score += 2;
}
if (score >= 90) {
return grades[0];
} else if (score >= 80) {
return grades[1];
} else if (score >= 70) {
return grades[2];
} else if (score >= 60) {
return grades[3];
} else if (score >= 50) {
return grades[4];
} else if (score >= 25) {
return grades[5];
} else if (score >= 0) {
return grades[6];
}
return "";
}
}