题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
import java.util.*;
public class Main{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
char [] arr = sc.nextLine().toCharArray();
int score = 5;
if(arr.length>=5 && arr.length<=7){
score+=5;
}else if(arr.length>7){
score+=20;
}
int num = 0;
int low = 0;
int high = 0;
int symbol = 0;
for(char x : arr){
if(x >='0' && x<'9'){
num++;
}else if(x>='a' && x<='z'){
low++;
}else if(x>='A' && x<='Z'){
high++;
}else if(x>='!' && x<='/'){
symbol++;
}else if(x>=':' && x<='@'){
symbol++;
}else if(x>='[' && x<='_'){
symbol++;
}else if(x>='{' && x<='~'){
symbol++;
}
}
//字母
score += low>0&&high>0 ? 20:low>0||high>0 ?10:0;
//数字
score += num>1?20:num==1?10:0;
//符号
score += symbol>1?25:symbol==1?10:0;
if(symbol>0 && num>0 && low>0 && high>0){
score+=5;
}else if(num>0 && symbol>0 && (low>0 || high>0)){
score+=3;
}else if(num>0 && (low>0 || high>0)){
score+=2;
}
String str;
if(score >= 90){
str="VERY_SECURE";
}else if(score >= 80){
str="SECURE";
}else if(score >= 70){
str="VERY_STRONG";
}else if(score >= 60){
str="STRONG";
}else if(score >= 50){
str="AVERAGE";
}else if(score >= 25){
str="WEAK";
}else{
str="VERY_WEAK";
}
System.out.println(str);
}
}