题解 | #密码强度等级#

密码强度等级

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

什么叫!!他马的!!屎山!!!!!

import java.util.*;
import java.util.regex.*;
public class Main{
    
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            String str = scan.nextLine();
            char[] ch = str.toCharArray();
            getScore(getLength(ch)+haveNum(ch)+haveWord(ch)+haveOther(ch)+award(ch));
            
        }
        scan.close();
    }
    
    public static int getLength(char[] ch){
        if(ch.length<=4){
            return 5;
        }
        else if(ch.length>=8){
            return 25;
        }
        else{
            return 10;
        }
    }
    
    public static int haveNum(char[] ch){
        int count = 0;
        for(char c : ch){
            if(String.valueOf(c).matches("[0-9]")){
                count++;
            }
        }
        if(count == 0){
            return 0;
        }
        else if(count == 1){
            return 10;
        }
        else{
            return 20;
        }
    }
    
    public static int haveWord(char[] ch){
        Pattern p1 = Pattern.compile("[a-z]");
        Pattern p2 = Pattern.compile("[A-Z]");
        if(p1.matcher(String.valueOf(ch)).find() && p2.matcher(String.valueOf(ch)).find()){
            return 20;
        }
        else{
            int count = 0;
            for(char c : ch){
                if(String.valueOf(c).matches("[a-z]") || String.valueOf(c).matches("[A-Z]")){
                    count++;
                }
            }
            if(count>0){
                return 10;
            }
            else{
                return 0;
            }
        }
    }
    
    public static int haveOther(char[] ch){
        int count = 0;
        for(char c : ch){
            if(String.valueOf(c).matches("[^a-zA-Z0-9]")){
                count++;
            }
        }
        if(count == 0){
            return 0;
        }
        else if(count == 1){
            return 10;
        }
        else{
            return 25;
        }
    }
    
    public static int award(char[] ch){
        int count = 0;
        int count1 = 0;
        int count2 = 0;
        Pattern p1 = Pattern.compile("[0-9]");
        if(p1.matcher(String.valueOf(ch)).find()){
            count++;
        }
        Pattern p2 = Pattern.compile("[a-z]");
        if(p2.matcher(String.valueOf(ch)).find()){
            count1++;
        }
        Pattern p3 = Pattern.compile("[A-Z]");
        if(p3.matcher(String.valueOf(ch)).find()){
            count1++;
        }
        Pattern p4 = Pattern.compile("[^a-zA-Z0-9]");
        if(p4.matcher(String.valueOf(ch)).find()){
            count2++;
        }
        if(count == 1 && count2 == 0 && count1>0){
            return 2;
        }
        else if(count == 1 && count2 == 1 && count1 == 1){
            return 3;
        }
        else if(count == 1 && count2 == 1 && count1 == 2){
            return 5;
        }
        else{
            return 0;
        }
    }
    
    public static void getScore(int n){
        if(n>=90){
            System.out.println("VERY_SECURE");
        }
        else if(n>=80 && n<90){
            System.out.println("SECURE");
        }
        else if(n>=70 && n<80){
            System.out.println("VERY_STRONG");
        }
        else if(n>=60 && n<70){
            System.out.println("STRONG");
        }
        else if(n>=50 && n<60){
            System.out.println("AVERAGE");
        }
        else if(n>=25 && n<50){
            System.out.println("WEAK");
        }
        else{
            System.out.println("VERY_WEAK");
        }
    }
}













全部评论

相关推荐

喵_coding:项目太烂了外卖+点评啊 而且寒假实习差不多到时候了 hc没多少了 要实在想要找那只能投投大厂试试了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
2025-12-17 16:48
今天九点半到公司,我跟往常一样先扫了眼电脑,屁活儿没有。寻思着没事干,就去蹲了个厕所,回来摸出手机刷了会儿。结果老板刚好路过,拍了我一下说上班别玩手机,我吓得赶紧揣兜里。也就过了四十分钟吧,我的直属领导把我叫到小隔间,上来就给我一句:“你玩手机这事儿把老板惹毛了,说白了,你可以重新找工作了,等下&nbsp;HR&nbsp;会来跟你谈。”&nbsp;我当时脑子直接宕机,一句话都没憋出来。后面&nbsp;HR&nbsp;找我谈话,直属领导也在旁边。HR&nbsp;说我这毛病不是一次两次了,属于屡教不改,不光上班玩手机,还用公司电脑看论文、弄学校的事儿。我当时人都傻了,上班摸鱼是不对,可我都是闲得发慌的时候才摸啊!而且玩手机这事儿,从来没人跟我说过后果这么严重,更没人告诉我在公司学个习也算犯错!连一次口头提醒都没有,哪儿来的屡教不改啊?更让我膈应的是,昨天部门刚开了会,说四个实习生里留一个转正,让大家好好表现。结果今天我就因为玩手机被开了。但搞笑的是,开会前直属领导就把我叫去小会议室,明明白白告诉我:“转正这事儿你就别想了,你的学历达不到我们部门要求,当初招你进来也没打算给你这个机会。”合着我没入贵厂的眼是吧?可我都已经被排除在转正名单外了,摸个鱼至于直接把我开了吗?真的太离谱了!
rush$0522:转正名单没进,大概率本来就没打算留你
摸鱼被leader发现了...
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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