题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
import java.util.Scanner;
import java.util.regex.Pattern;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int count =0;
String str = in.next();
int len = str.length();
boolean containDigit=false;
boolean containLetter=false;
boolean containLetterboth=false;
boolean containp=false;
if(len<=4) count+=5;
else if(len<=7) count+=10;
else count+=25;
if((len-str.replaceAll("[A-Za-z]","").length())>0){
containLetter=true;
count+=10;
//System.out.println("containLetter");
if(((len-str.replaceAll("[A-Z]","").length())>0)&&((len-str.replaceAll("[a-z]","").length())>0)) {
count+=10;
containLetterboth=true;
//System.out.println("containLetterboth");
}
}
if((len-str.replaceAll("[0-9]","").length())>1){
containDigit=true;
count+=20;
//System.out.println("containDigit");
}else if((len-str.replaceAll("[0-9]","").length())>0) {
count+=10;
containDigit=true;
//System.out.println("containDigit");
}
if((str.replaceAll("[A-Za-z0-9]","").length())>0){
containp=true;
count+=10;
//System.out.println("containp");
if((str.replaceAll("[A-Za-z0-9]","").length())>1)
count+=15;
}
if(containDigit&&containLetterboth&&containp){
count+=5;
}else if(containDigit&&containLetter&&containp)
count+=3;
else if(containDigit&&containLetter) count+=2;
if(count>=90) System.out.print("VERY_SECURE");
else if(count>=80) System.out.print("SECURE");
else if(count>=70) System.out.print("VERY_STRONG");
else if(count>=60) System.out.print("STRONG");
else if(count>=50) System.out.print("AVERAGE");
else if(count>=25) System.out.print("WEAK");
else System.out.print("VERY_WEAK");
}
}