题解 | #密码强度等级#

密码强度等级

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String str = sc.nextLine();
            int score = 0;
            int length = str.length();
            // 密码长度得分
            if(length <= 4){
                score += 5;
            }else if(length <= 7 && length >= 5){
                score += 10;
            }else if(length >= 8){
                score += 25;
            }

            int lowerLetterCount = 0;
            int upperLetterCount = 0;
            int numberCount = 0;
            int symbolCount = 0;
            char[] chars = str.toCharArray();
            for(char c : chars){
                if(c >= 'a' && c <= 'z'){
                    lowerLetterCount++;
                }else if(c >= 'A' && c <= 'Z'){
                    upperLetterCount++;
                }else if(c >= '0' && c <= '9'){
                    numberCount++;
                }else{
                    symbolCount++;
                }
            }
            
            // 字母得分
            if(lowerLetterCount > 0 && upperLetterCount > 0){
                score += 20;
            }else if(lowerLetterCount == 0 || upperLetterCount == 0){
                score += 10;
            }
            // 数字得分
            if(numberCount > 1){
                score += 20;
            }else if(numberCount == 1){
                score += 10;
            }
            // 符号得分
            if(symbolCount > 1){
                score += 25;
            }else if(symbolCount == 1){
                score += 10;
            }

            // 奖励
            if(lowerLetterCount > 0 && upperLetterCount > 0 && numberCount > 0 && symbolCount > 0){
                score += 5;
            }else if((lowerLetterCount > 0 || upperLetterCount > 0) && numberCount > 0 && symbolCount > 0){
                score += 3;
            }else if((lowerLetterCount > 0 || upperLetterCount > 0) && numberCount > 0){
                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 if(score >= 0){
                System.out.println("VERY_WEAK");
            }
        }
    }
}

全部评论

相关推荐

08-11 17:48
辽宁大学 财务
投秋招已经快两周,每天就是投投投到厌倦然后躺床上刷痘印越刷越焦虑
驼瑞驰_招募评论官版...:你把牛客放中间,那你必得offer的
点赞 评论 收藏
分享
08-07 11:47
门头沟学院 Java
快手你的进度好快啊,可是我感觉我还没做好准备8.4投递8.7hr初筛-用人部门筛选
瞒着老板找实习:2号投敌 4号约面 今天一面已挂 哈哈
投递快手等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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