题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int sort = 0;
String password = sc.nextLine();
char[] ch = password.toCharArray();
//密码长度
if (password.length() < 5) {
sort += 5;
} else if (password.length() > 7) {
sort += 25;
} else {
sort += 10;
}
//字母
int upnum = 0;
int lwnum = 0;
for (int i = 0; i < ch.length; i++) {
if (Character.isUpperCase(ch[i])) {
upnum++;
} else if (Character.isLowerCase(ch[i])) {
lwnum++;
}
}
if ((upnum == 0 && lwnum != 0) || (lwnum == 0 && upnum != 0)) {
sort += 10;
} else if (upnum > 0 && lwnum > 0) {
sort += 20;
}
//数字
int sx = 0;
for (int i = 0; i < ch.length; i++) {
if (Character.toString(ch[i]).matches("[0-9]")) {
sx++;
}
}
if (sx == 1) {
sort += 10;
} else if (sx > 1) {
sort += 20;
}
//符号
int nums = 0;
for (int i = 0; i < ch.length; i++) {
if ((int)ch[i] >= 33 && (int)ch[i] <= 47) {
nums++;
} else if ((int)ch[i] >= 58 && (int)ch[i] <= 64) {
nums++;
} else if ((int)ch[i] >= 91 && (int)ch[i] <= 96) {
nums++;
} else if ((int)ch[i] >= 123 && (int)ch[i] <= 126) {
nums++;
}
}
if (nums == 1) {
sort += 10;
} else if (nums > 1) {
sort += 25;
}
//奖励
if ((nums == 0 && sx > 0 && upnum > 0) || (nums == 0 && sx > 0 && lwnum > 0)) {
sort += 2;
} else if ((nums > 0 && sx > 0 && upnum > 0 && lwnum == 0) || (nums > 0 &&
sx > 0 && lwnum > 0 && upnum == 0)) {
sort += 3;
} else if (nums > 0 && sx > 0 && upnum > 0 && lwnum > 0) {
sort += 5;
}
//评分
if (sort >= 90) {
System.out.print("VERY_SECURE");
} else if (sort >= 80 && sort < 90) {
System.out.print("SECURE");
} else if (sort >= 70 && sort < 80) {
System.out.print("VERY_STRONG");
} else if (sort >= 60 && sort < 70) {
System.out.print("STRONG");
} else if (sort >= 50 && sort < 60) {
System.out.print("AVERAGE");
} else if (sort >= 25 && sort < 50) {
System.out.print("WEAK");
} else if (sort >= 0 && sort < 25) {
System.out.print("VERY_WEAK");
}
}
}
上海得物信息集团有限公司公司福利 1166人发布
查看25道真题和解析