题解 | #密码强度等级#

密码强度等级

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

import java.util.Scanner;
import java.util.regex.Pattern;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int count =0;
        String str = in.next();
        int len = str.length();
        boolean containDigit=false;
        boolean containLetter=false;
        boolean containLetterboth=false;
        boolean containp=false;
        if(len<=4) count+=5;
        else if(len<=7) count+=10;
        else count+=25;
        if((len-str.replaceAll("[A-Za-z]","").length())>0){
            containLetter=true;
            count+=10;
            //System.out.println("containLetter");
            if(((len-str.replaceAll("[A-Z]","").length())>0)&&((len-str.replaceAll("[a-z]","").length())>0)) {
                count+=10;
                containLetterboth=true;
                //System.out.println("containLetterboth");
            }
        }
        if((len-str.replaceAll("[0-9]","").length())>1){
            containDigit=true;
            count+=20;
            //System.out.println("containDigit");
        }else if((len-str.replaceAll("[0-9]","").length())>0) {
            count+=10;
            containDigit=true;
            //System.out.println("containDigit");
        }
        if((str.replaceAll("[A-Za-z0-9]","").length())>0){
            containp=true;
            count+=10;
            //System.out.println("containp");
            if((str.replaceAll("[A-Za-z0-9]","").length())>1)
                count+=15;
        }
        if(containDigit&&containLetterboth&&containp){
            count+=5;
        }else if(containDigit&&containLetter&&containp)
            count+=3;
        else if(containDigit&&containLetter) count+=2;
        if(count>=90) System.out.print("VERY_SECURE");
        else if(count>=80) System.out.print("SECURE");
        else if(count>=70) System.out.print("VERY_STRONG");
        else if(count>=60) System.out.print("STRONG");
        else if(count>=50) System.out.print("AVERAGE");
        else if(count>=25) System.out.print("WEAK");
        else System.out.print("VERY_WEAK");
        

    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 17:13
点赞 评论 收藏
分享
07-07 12:25
门头沟学院 Java
程序员牛肉:你这个智邮公司做的就是那个乐山市税务系统的服务吗?
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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