这种题考察的是你想不想做

密码强度等级

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

import java.util.Locale;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String password = in.nextLine();
        int score = 0;
        int length = password.length();
        // 密码长度分
        if (length <= 4) {
            score += 5;
        } else if (length <= 7) {
            score += 10;
        } else {
            score += 25;
        }

        // 字母
        int lowerCase = 0;
        int upperCase = 0;
        // 数字
        int digit = 0;
        // 符号
        int symbol = 0;
        char[] charArray = password.toCharArray();
        // 统计
        for (int i = 0; i < charArray.length; i++) {
            char c = charArray[i];
            if (Character.isLowerCase(c)) {
                lowerCase++;
            } else if (Character.isUpperCase(c)) {
                upperCase++;
            } else if (Character.isDigit(c)) {
                digit++;
                // 不是数字和字母
            } else {
                symbol++;
            }
        }

        // 全是小/大写字母
        if ((lowerCase != 0 && upperCase == 0) || (lowerCase == 0 && upperCase != 0)) {
            score += 10;
            // 大小写混合
        } else if (lowerCase != 0) {
            score += 20;
        }

        // 数字分
        if (digit == 1) {
            score += 10;
        } else if (digit > 1) {
            score += 20;
        }

        // 符号分
        if (symbol == 1) {
            score += 10;
        } else if (symbol > 1) {
            score += 25;
        }

        // 奖励分
        int reward = 0;
        if (lowerCase != 0 && upperCase != 0 && digit != 0 && symbol != 0) {
            reward = 5;
        } else if ((lowerCase != 0 || upperCase != 0) && digit != 0 && symbol != 0) {
            reward = 3;
        } else if ((lowerCase != 0 || upperCase != 0) && digit != 0) {
            reward = 2;
        }

        score += reward;

        // 根据分数输出
        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 if (score >= 0) {
            System.out.println("VERY_WEAK");
        }
    }
}

全部评论

相关推荐

07-15 14:14
门头沟学院 Java
7.10投递7.15感谢信
投递地平线等公司7个岗位
点赞 评论 收藏
分享
07-02 22:46
门头沟学院 Java
码农索隆:hr:“管你投没投,先挂了再说”
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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