题解 | #密码强度等级#

密码强度等级

http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361

public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            while(sc.hasNextLine()) {
                String str = sc.nextLine();
                int score = 0;
                int count = 0;
                if (str.length() <= 4) {
                    score += 5;
                } else if (str.length() >= 5 && str.length() <=7) {
                    score += 10;
                } else {
                    score += 25;
                }
                String str1 = str.replaceAll("[a-zA-Z]", "");
                String str2 = str.replaceAll("[^a-z]", "");
                String str3 = str.replaceAll("[^A-Z]", "");
                if (str1.length() == str.length()) {
                    score += 0;
                } else {
                        if (str2.length() == 0 || str3.length() == 0) {
                            score += 10;
                            count++;
                        } else {
                            score += 20;
                            count += 2;
                        }
                }
                String str4 = str.replaceAll("[0-9]", "");
                String str5 = str.replaceAll("[^0-9]", "");
                if (str4.length() == str.length()) {
                    score += 0;
                } else {
                    count++;
                        if (str5.length() == 1) {
                            score += 10;
                        } else {
                            score += 20;
                        }
                }
                String str6 = str.replaceAll("[^a-zA-Z0-9]", "");
                String str7 = str.replaceAll("[a-zA-Z0-9]", "");
                if (str6.length() == str.length()) {
                    score += 0;
                } else {
                    count++;
                        if (str7.length() == 1) {
                            score += 10;
                        } else {
                            score += 25;
                        }
                }
                if(count == 4) {
                    score += 5;
                } else if(count == 3) {
                    score += 3;
                } else {
                    score += 2;
                }
                if (score >= 90) {
                    System.out.println("VERY_SECURE");
                    continue;
                } else if (score >= 80) {
                    System.out.println("SECURE");
                    continue;
                } else if (score >= 70) {
                    System.out.println("VERY_STRONG");
                    continue;
                } else if (score >= 60) {
                    System.out.println("STRONG");
                    continue;
                } else if (score >= 50) {
                    System.out.println("AVERAGE");
                    continue;
                } else if (score >= 25) {
                    System.out.println("WEAK");
                    continue;
                } else {
                    System.out.println("VERY_WEAK");
                }
                
            }
        }
}
全部评论

相关推荐

点赞 评论 收藏
分享
感性的干饭人在线蹲牛友:🐮 应该是在嘉定这边叭,禾赛大楼挺好看的
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务