题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; import static java.util.Arrays.*; import static java.util.stream.Stream.*; public class Main { public static void main(String[] args) throws IOException { //testCompletePack(); testTh(); } private static void testTh() throws IOException { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); String str; while ((str=bf.readLine())!=null){ int length = str.length(); int score=0; if (length<=4){ score=score+5; }else if (length<=7){ score=score+10; }else { score=score+25; } int flagA=0; int flagB=0; int flagN=0; int flagC=0; char[] chars = str.toCharArray(); for (char aChar : chars) { if (aChar>='a'&&aChar<='z'){ flagA=1; }else if (aChar>='A'&&aChar<='Z'){ flagB=1; } else if (aChar>='0'&&aChar<='9') { flagN++; }else { flagC++; } } if (flagA==1&&flagB==1){ score=score+20; } else if (flagA==1||flagB==1) { score=score+10; } if (flagN==1){ score=score+10; }else if (flagN>1){ score=score+20; } if (flagC==1){ score=score+10; } else if (flagC>1) { score=score+25; } if (flagA==1&&flagB==1&&flagN>=1&&flagC>=1){ score=score+5; } else if ((flagA==1||flagB==1)&&flagC>=1&&flagN>=1) { score=score+3; } else if ((flagA==1||flagB==1)&&flagN>=1) { score=score+2; } if (score>=0&&score<25){ System.out.println("VERY_WEAK"); } else if (score<50) { System.out.println("WEAK"); } else if (score<60) { System.out.println("AVERAGE"); } else if (score<70) { System.out.println("STRONG"); } else if (score<80) { System.out.println("VERY_STRONG"); } else if (score<90) { System.out.println("SECURE"); }else { System.out.println("VERY_SECURE"); } } } }