题解 | #密码强度等级#

密码强度等级

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");
        }
    }
}













全部评论

相关推荐

来个大佬救一下,为上投了都是石沉大海了,没实习经历的话怕秋招直接进不了面。什么实习这么难找,基本
心态爆炸了:现在正式的岗位都少,实习基本不咋招的,除了大厂,中小企业其实没那么多岗位需求,就算是有,大多都是招一两个廉价劳动力,同时,他们也会希望你一来就能干活的,没时间培训你,就让你了解公司的项目,你了解完就可以开始干活。再者是,很多低质量的实习其实用处没有那么大的。我去年也是找实习找到破防,最后去了一家深圳的小公司实习,工作对我来说很简单,甚至不如我在学校做的项目,秋招的时候,这段实习经历也并没有帮上什么忙,投递简历,依旧非常低的回复率。低回复率是常态,尤其是找实习,找不到,那就把重心放在优化自己的简历和项目,多看八股文,锻炼自己的面试能力,多看别人的面经,自己模拟面试,等秋招的时候,只要有那么寥寥几次,好好抓住那几次机会。
点赞 评论 收藏
分享
06-11 17:39
门头沟学院 Java
小呆呆的大鼻涕:卧槽,用户彻底怒了
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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