题解 | #密码强度等级#

密码强度等级

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String pswd = in.nextLine();
        int len = pswd.length();
        if(len<1 || len>300 || "".equals(pswd)) return;
        int score = calScore(pswd);
        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");
    }

    public static int calScore(String s){
        int res = 0;
        if(s.length() >= 8) res+=25;
        else if(s.length()>=5 && s.length()<=7) res+=10;
        else res+=5;

        int countN = 0;
        int countS = 0;
        int countE = 0;
        int counte = 0;
        for(int i=0; i<s.length(); i++){
            char c = s.charAt(i);
            if(c>='0' && c<='9') countN++;
            //if((c>='!' && c<='/') || (c>=':' && c<='@') || (c>='[' && c<='`') || (c>='{' && c<='~'))
            if((c>=0x21 && c<=0x2F) || (c>=0x3A && c<=0x40) || (c>=0x5B && c<=0x60) || (c>=0x7B && c<=0x7E))
                countS++;
            if(c>='a' && c<='z') counte++;
            else if(c>='A' && c<='Z') countE++;
        }

        if(countS > 1) res+=25;
        else if(countS == 1) res+=10;
        if(countN > 1) res+= 20;
        else if(countN == 1) res+=10;
        if(countE>0 && counte>0) res+=20;
        else if(countE>0 || counte>0) res+=10;
        if(countE>0 && counte>0 && countN>0 && countS>0) res+=5;
        else if((counte + countE)>0 && countN>0 && countS>0) res+=3;
        else if((counte + countE)>0 && countN>0) res+=2;
        return res;
    }
}

全部评论

相关推荐

像好涩一样好学:这公司我也拿过 基本明确周六加班 工资还凑活 另外下次镜头往上点儿
点赞 评论 收藏
分享
11-27 12:36
已编辑
门头沟学院 前端工程师
Apries:这个阶段来说,很厉害很厉害了,不过写的简历确实不是很行,优势删掉吧,其他的还行
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务