题解 | #HJ087 密码强度等级#

密码强度等级

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

import java.util.Scanner;

/**
 * HJ87 密码强度等级 - 简单
 */
public class HJ087 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String input = sc.nextLine();
            int score = 0;
            if (input.length() <= 4) {
                score += 5;
            } else if (input.length() < 8) {
                score += 10;
            } else {
                score += 25;
            }
            if (input.matches(".*[A-Za-z]+.*")) {
                if (input.matches(".*[A-Z].*")
                        && input.matches(".*[a-z].*")) {
                    score += 20;
                } else {
                    score += 10;
                }
            }
            if (input.matches(".*[0-9]+.*")) {
                if (input.matches(".*[0-9].*[0-9].*")) {
                    score += 20;
                } else {
                    score += 10;
                }
            }
            if (input.matches(".*[^A-Za-z0-9]+.*")) {
                if (input.matches(".*[^A-Za-z0-9].*[^A-Za-z0-9].*")) {
                    score += 25;
                } else {
                    score += 10;
                }
            }
            if (input.matches(".*[0-9]+.*")) {
                if (input.matches(".*[A-Z].*")
                        && input.matches(".*[a-z].*")
                        && input.matches(".*[^A-Za-z0-9]+.*")) {
                    score += 5;
                } else if (input.matches(".*[A-Za-z]+.*")) {
                    if (input.matches(".*[^A-Za-z0-9]+.*")) {
                        score += 3;
                    } else {
                        score += 2;
                    }
                }
            }
            if (score >= 90) {
                System.out.println("VERY_SECURE");
            } else if (score >= 80) {
                System.out.println("SECURE");
            } else if (score >= 70) {
                System.out.println("VERY_STRONG");
            } else if (score >= 60) {
                System.out.println("STRONG");
            } else if (score >= 50) {
                System.out.println("AVERAGE");
            } else if (score >= 25) {
                System.out.println("WEAK");
            } else {
                System.out.println("VERY_WEAK");
            }
        }
        sc.close();
    }
}
全部评论

相关推荐

想进开水团喝开水:哦 给我一个 就算你真拿到牛友也会为你开心的
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-21 11:29
已编辑
斯卡蒂味的鱼汤:知道你不会来数马,就不捞你😂最近数马疯狂扩招,招聘要求挺低的,你能力肯定够,应该就是因为太强了,知道你不会来才不捞你
投递腾讯云智研发等公司7个岗位
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务