首页 > 试题广场 >

密码强度等级

[编程题]密码强度等级
  • 热度指数:133874 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。

一、密码长度:
5 分: 小于等于4 个字符
10 分: 5 到7 字符
25 分: 大于等于8 个字符

二、字母:
0 分: 没有字母
10 分: 密码里的字母全都是小(大)写字母
20 分: 密码里的字母符合”大小写混合“

三、数字:
0 分: 没有数字
10 分: 1 个数字
20 分: 大于1 个数字

四、符号:
0 分: 没有符号
10 分: 1 个符号
25 分: 大于1 个符号

五、奖励(只能选符合最多的那一种奖励):
2 分: 字母和数字
3 分: 字母、数字和符号
5 分: 大小写字母、数字和符号

最后的评分标准:
>= 90: 非常安全
>= 80: 安全(Secure)
>= 70: 非常强
>= 60: 强(Strong)
>= 50: 一般(Average)
>= 25: 弱(Weak)
>= 0:  非常弱(Very_Weak)

对应输出为:

VERY_SECURE
SECURE
VERY_STRONG
STRONG
AVERAGE
WEAK
VERY_WEAK

请根据输入的密码字符串,进行安全评定。

注:
字母:a-z, A-Z
数字:0-9
符号包含如下: (ASCII码表可以在UltraEdit的菜单view->ASCII Table查看)
!"#$%&'()*+,-./     (ASCII码:0x21~0x2F)
:;<=>?@             (ASCII码:0x3A~0x40)
[\]^_`              (ASCII码:0x5B~0x60)
{|}~                (ASCII码:0x7B~0x7E)

提示:
1 <= 字符串的长度<= 300

输入描述:

输入一个string的密码



输出描述:

输出密码等级

示例1

输入

38$@NoNoN

输出

VERY_SECURE

说明

样例的密码长度大于等于8个字符,得25分;大小写字母都有所以得20分;有两个数字,所以得20分;包含大于1符号,所以得25分;由于该密码包含大小写字母、数字和符号,所以奖励部分得5分,经统计得该密码的密码强度为25+20+20+25+5=95分。
         
示例2

输入

Jl)M:+

输出

AVERAGE

说明

示例2的密码强度为10+20+0+25+0=55分。        
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;

        while ((line = br.readLine()) != null) {
            // 计算大写字母 小写字母 数字 特殊字符的个数

            HashMap<String, Integer> map = new HashMap<>();
            for (int i = 0; i < line.length(); i++) {
                char c = line.charAt(i);
                if (Character.isDigit(c)) {
                    String key = "digit";
                    map.put(key, map.getOrDefault(key, 0) + 1);
                } else if (Character.isUpperCase(c)) {
                    String key = "upper";
                    map.put(key, map.getOrDefault(key, 0) + 1);
                } else if (Character.isLowerCase(c)) {
                    String key = "lower";
                    map.put(key, map.getOrDefault(key, 0) + 1);
                } else {
                    String key = "special";
                    map.put(key, map.getOrDefault(key, 0) + 1);
                }

            }

            // 计算得分
            int score = 0;

            // TODO 根据长度
            if (line.length() >= 8) {
                score += 25;
            } else if (line.length() >= 5) {
                score += 10;
            } else {
                score += 5;
            }

            // TODO 是否有字母
            int upperCount = map.getOrDefault("upper", 0);
            int lowerCount = map.getOrDefault("lower", 0);
            if (upperCount == 0 && lowerCount == 0) {
                // 没有字母
                score += 0;
            } else if (upperCount > 0 && lowerCount > 0) {
                // 大小写字母都有
                score += 20;
            } else {
                // 只有大写 或者 小写字母
                score += 10;
            }

            // TODO 是否有数字
            int digit = map.getOrDefault("digit", 0);
            if (digit > 1) {
                score += 20;
            } else if (digit == 1) {
                score += 10;
            } else {
                score += 0;
            }

            // TODO 是否有符号
            int special = map.getOrDefault("special", 0);
            if (special > 1) {
                score += 25;
            } else if (special == 1) {
                score += 10;
            } else {
                score += 0;
            }


            // TODO 奖励分
            if (upperCount > 0 && lowerCount > 0 && digit > 0 && special > 0) {
                // 5 分: 大小写字母、数字和符号
                score += 5;
            } else if ((upperCount + lowerCount) > 0 && digit > 0 && special > 0) {
                // 3 分: 字母、数字和符号
                score += 3;
            } else if ((upperCount + lowerCount) > 0 && digit > 0) {
                // 2 分: 字母和数字
                score += 2;
            }

            // TODO 评分标准
            //System.out.println("score = " + score);
            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");
            }
        }
    }
}

发表于 2023-08-13 16:56:26 回复(0)
import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        HashMap<String,Integer> depth=new HashMap<>();
        //等级划分
        depth.put("length",0);
        depth.put("letter",0);
        depth.put("num",0);
        depth.put("sym",0);
        depth.put("pre",0);
        String str=in.nextLine();

        //判断密码长度
        if(str.length()<=4){
            depth.put("length",5);
        }else if(str.length()<=7){
            depth.put("length",10);
        }else{
            depth.put("length",25);
        }
        //判断字母情况和判断数字情况和符号情况
        //符号等级
        int symSum=0;
        //数字等级
        int numSum=0;
        //小写字母
        int letterLow=0;
        //大写字母
        int letterUpper=0;
        for(int i=0;i<str.length();i++){
            //有小写字母
            if(Character.isLowerCase(str.charAt(i))){
                letterLow=1;
                if(letterUpper==1&&numSum>=2&&symSum>=2){
                    break;
                }
            //有大写字母
            }else if(Character.isUpperCase(str.charAt(i))){
                letterUpper=1;
                if(letterLow==1&&numSum>=2&&symSum>=2){
                    break;
                }
            }
            if(Character.isDigit(str.charAt(i))){
                numSum++;
            }
            if(!Character.isDigit(str.charAt(i))&&!Character.isLetter(str.charAt(i))){
                symSum++;
            }

        }
        //字母
        if(letterLow==0&&letterUpper==0){
            depth.put("letter",0);
        }else if(letterLow==1&&letterUpper==1){
            depth.put("letter",20);
        }else if(letterLow==1||letterUpper==1){
            depth.put("letter",10);
        }
        //数字
        if(numSum==0){
            depth.put("num",0);
        }else if(numSum==1){
            depth.put("num",10);
        }else if(numSum>=2){
            depth.put("num",20);
        }
        //符号
        if(symSum==0){
            depth.put("sym",0);
        }else if(symSum==1){
            depth.put("sym",10);
        }else if(symSum>=2){
            depth.put("sym",25);
        }
        //奖励
        if(depth.get("letter")==20&&depth.get("num")>=10&&depth.get("sym")>=10){
            depth.put("pre",5);
        }else if(depth.get("letter")>=10&&depth.get("num")>=10&&depth.get("sym")>=10){
            depth.put("pre",3);
        }else if(depth.get("letter")>=10&&depth.get("num")>=10){
            depth.put("pre",2);     
        }
        int sum=depth.get("length")+depth.get("letter")+depth.get("num")+depth.get("sym")+depth.get("pre");
        if(sum>=90){
            System.out.print("VERY_SECURE");
        }else if(sum>=80){
            System.out.print("SECURE");
        }else if(sum>=70){
            System.out.print("VERY_STRONG");
        }else if(sum>=60){
            System.out.print("STRONG");
        }else if(sum>=50){
            System.out.print("AVERAGE");
        }else if(sum>=25){
            System.out.print("WEAK");
        }else if(sum>=0){
            System.out.print("VERY_WEAK");
        }
        
    }
}

发表于 2023-06-06 15:45:43 回复(0)
要点耐心。。。
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String line = in.nextLine();
            int grade = 0;
            grade += new Length().grade(line);
            grade += new Letter().grade(line);
            grade += new Number().grade(line);
            grade += new Symbol().grade(line);
            grade += new Encourage().grade(line);
            OutType print;
            if (grade >= 90) {
                print = OutType.VERY_SECURE;
            } else if (grade >= 80) {
                print = OutType.SECURE;
            } else if (grade >= 70) {
                print = OutType.VERY_STRONG;
            } else if (grade >= 60) {
                print = OutType.STRONG;
            } else if (grade >= 50) {
                print = OutType.AVERAGE;
            } else if (grade >= 25) {
                print = OutType.WEAK;
            } else {
                print = OutType.VERY_WEAK;
            }
            System.out.println(print);
        }
    }

    enum OutType {
        VERY_SECURE, SECURE, VERY_STRONG, STRONG, AVERAGE, WEAK, VERY_WEAK
    }
}

interface ValidRule {
    public int grade(String str);
}

class Length implements ValidRule {
    public int grade(String str) {
        if (str.length() >= 8) {
            return 25;
        } else if (str.length() >= 5) {
            return 10;
        } else {
            return 5;
        }
    }
}

class Letter implements ValidRule {
    public int grade(String str) {
        boolean upper = false;
        boolean lower = false;
        for (int i = 0; i < str.length(); i++) {
            if (Character.isUpperCase(str.charAt(i))) {
                upper = true;
            } else if (Character.isLowerCase(str.charAt(i))) {
                lower = true;
            }

            if (upper && lower) {
                break;
            }
        }
        if (upper && lower) {
            return 20;
        } else if (upper || lower) {
            return 10;
        } else {
            return 0;
        }
    }
}

class Number implements ValidRule {
    public int grade(String str) {
        int count = 0;
        for (int i = 0; i < str.length(); i++) {
            if (Character.isDigit(str.charAt(i))) {
                count++;
            }
            if (count > 1) {
                break;
            }
        }
        if (count > 1) {
            return 20;
        } else if (count > 0) {
            return 10;
        } else {
            return 0;
        }
    }
}

class Symbol implements ValidRule {
    public int grade(String str) {
        int count = 0;
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isLetterOrDigit(str.charAt(i))) {
                count++;
            }
            if (count > 1) {
                break;
            }
        }
        if (count > 1) {
            return 25;
        } else if (count > 0) {
            return 10;
        } else {
            return 0;
        }
    }
}

class Encourage implements ValidRule {
    public int grade(String str) {
        boolean num = false, symbol = false, upper = false, lower = false;
        for (int i = 0; i < str.length(); i++) {
            if (Character.isUpperCase(str.charAt(i))) {
                upper = true;
            } else if (Character.isLowerCase(str.charAt(i))) {
                lower = true;
            } else if (Character.isDigit(str.charAt(i))) {
                num = true;
            } else {
                symbol = true;
            }
        }
        if (upper && lower && num && symbol) {
            return 5;
        } else if ((upper || lower) && num && symbol) {
            return 3;
        } else if ((upper || lower) && num) {
            return 2;
        }
        return 0;
    }
}

发表于 2023-05-14 22:45:13 回复(0)
不会正则表达式,但还是写对了,100%通过开心
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String list  = in.next();
        int a = length1(list);
        int b = chars(list);
        int c = number(list);
        int d = charr(list);
        int e = 0;
        if( b> 0 && c >0 && d==0 ){
            e = 2;
        }else if(b> 0 && b<10 && c >0 && d > 0){
            e = 3;
        }else if(b == 20 && c >0 && d > 0){
            e = 5;
        }
        int answer = length1(list) + chars(list) + number(list)+ charr(list)+e;
        answer(answer);
        }
    
    private static int length1(String list) {
        int c = 0;
        if (list.length() <= 4) {
            c = 5;
        } else if (list.length() > 4 && list.length() <= 7) {
            c = 10;
        } else {
            c = 25;
        }
        return c ;
    }
    private static int chars (String list) {
        int a = 0;
        int b = 0;
        int c = 0;
        for (int i = 0 ; i < list.length(); i++) {
            if (list.charAt(i) >= 'a' && list.charAt(i) <= 'z') {
                a++;
            } else if (list.charAt(i) >= 'A' && list.charAt(i) <= 'Z') {
                b++;
            }
        }
        if (a == 0 && b == 0) {
            c = 0;
        } else if ((a != 0 && b == 0) || (a == 0 && b != 0)) {
            c = 10;
        } else if ( a != 0 && b != 0) {
            c = 20;
        }
        return c;
    }
    private static int number(String list) {
        int a = 0;
        int b = 0;
        for (int i = 0 ; i < list.length() ; i++) {
            if ( list.charAt(i) >= '0' && list.charAt(i) <= '9') {
                a++;
            }
        }
        if (a == 0) {
            b = 0;
        } else if (a == 1) {
            b = 10 ;
        } else if( a > 1){
            b = 20;
        }
        return b;
    }
    private static int charr (String list) {
        int a = 0;
        int b = 0;
        for (int i = 0 ; i < list.length() ; i++) {
            char aaq = list.charAt(i);
            if ( aaq < '0' || (aaq >= '9' && aaq < 'A') || (aaq >'Z' && aaq < 'a') ||    aaq >'z' ) {
                a++;
            }
        }
        if (a == 0) {
            b = 0;
        } else if (a == 1) {
            b = 10 ;
        } else {
            b = 25;
        }
        return b;
    }
    private static void answer(int number) {
        int f = number;
        if (f >= 90) {
            System.out.println("VERY_SECURE");
        } else if (f < 90 && f >= 80) {
            System.out.println("SECURE");
        } else if (f < 80 && f >= 70) {
            System.out.println("VERY_STRONG");
        } else if (f < 70 && f >= 60) {
            System.out.println("STRONG");
        } else if (f < 60 && f >= 50) {
            System.out.println("AVERAGE");
        } else if (f < 50 && f >= 25) {
            System.out.println("WEAK");
        } else if (f < 25 && f >= 0) {
            System.out.println("VERY_WEAK");
        }
        }
    }

发表于 2023-03-26 23:20:47 回复(0)
13ms  超过95%
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String password = br.readLine();
        int length = len(password);
        int letter = isLetter(password);
        int digit = isDigital(password);
        int signal = isSignal(password);
        show(letter, digit, signal, length);
    }
    public static int len(String password){
        int score = 0;
        if(password.length() <= 4){
            score = 5;
        }else if(password.length() <= 7 && password.length() >= 5){
            score = 10;
        }else{
            score = 25;
        }
        return score;
    }
    public static int isLetter(String password){
        int score = 0;
        for(int i = 0; i < password.length();i++){
            if(!Character.isLetter(password.charAt(i))){
                continue;
            }
            // 已经确定i位置上是字母
            score = 10;
            if(i == password.length()){  // 如果字母出现在最后一位
                score = 10;
                return score;
            }
            boolean flag1 = Character.isUpperCase(password.charAt(i));
            for(int j = i + 1; j < password.length(); j++){
                if(!Character.isLetter(password.charAt(j))){
                    continue;
                }
                //已经确定j位置也是字母
                boolean flag2 = Character.isUpperCase(password.charAt(j));
                if(flag1 == flag2){
                    score = 10;
                }else{
                    score = 20;
                    return score;
                }
                if(j == password.length()){
                    return score;
                }
            }
        }
        return score;
    }
    public static int isDigital(String password){
        int count = 0;
        for(int i = 0; i < password.length(); i++){
            if(Character.isDigit(password.charAt(i))){
                count++;
            }
            if(count > 1){  // 提前结束遍历
                return 20;
            }
        }
        return count > 0 ? 10 : 0;
    }
    public static int isSignal(String password){
        String sigStr = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
        int score = 0;
        int count = 0;
        for (int i = 0; i < password.length(); i++) {
            if(sigStr.contains(String.valueOf(password.charAt(i)))){
                count++;
            }
            if(count > 1){
                return 25;
            }
        }
        return count > 0 ? 10 : 0;
    }
    public static void show(int letter, int digit, int signal, int length){
        int score = 0;
        int grade = 0;
        if(letter == 10 && digit != 0){
            grade = 2;
        }
        if(letter == 10 && digit != 0 && signal != 0){
            grade = 3;
        }
        if(letter == 20 && digit != 0 && signal != 0){
            grade = 5;
        }
        score = letter + digit + signal + grade + length;
        switch(score / 10){
            case 9:
                System.out.println("VERY_SECURE");
                break;
            case 8:
                System.out.println("SECURE");
                break;
            case 7:
                System.out.println("VERY_STRONG");
                break;
            case 6:
                System.out.println("STRONG");
                break;
            case 5:
                System.out.println("AVERAGE");
                break;
            case 4:
            case 3:
            case 2:
                System.out.println("WEAK");
                break;
            default:
                System.out.println("VERY_WEAK");
        }
    }
}


发表于 2022-08-17 12:25:52 回复(0)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String in = br.readLine().trim();
        //题目设定 1<= 字符串长度 <= 300

        System.out.println(score(in));

    }
    //求长度得分
    public static int scoreByLength(String in) {
        int len = in.length();
        if (len >= 8)
            return 25;
        else if (len >= 5)
            return 10;
        else
            return 5;
    }
    //英文字母得分
    public static int scoreByLetter(String in) {
        String capital = in.replaceAll("[^A-Z]", "");
        String lower = in.replaceAll("[^a-z]", "");

        if (capital.length() == 0 && lower.length() == 0)
            return 0;
        if (capital.length() != 0 && lower.length() != 0)
            return 20;
        return 10;
    }
    //阿拉伯数字得分
    public static int scoreByDigit(String in) {
        String digit = in.replaceAll("[^0-9]", "");
        if (digit.length() == 0)
            return 0;
        else if (digit.length() == 1)
            return 10;
        else
            return 20;
    }
    //特殊字符得分
    public static int scoreBySgin(String in) {
        String sgin = in.replaceAll("[a-zA-Z0-9]", "");
        if (sgin.length() == 0)
            return 0;
        else if (sgin.length() == 1)
            return 10;
        else
            return 25;
    }
    //奖励得分
    public static int scoreByReward(String in) {
        if (scoreByDigit(in) != 0 && scoreByLetter(in) == 10 && scoreBySgin(in) != 0)
            return 3;
        if (scoreByDigit(in) != 0 && scoreByLetter(in) == 20 && scoreBySgin(in) != 0)
            return 5;
        if (scoreByDigit(in) != 0 && scoreByLetter(in) != 0)
            return 2;
        return 0;
    }
    //根据得分输出密码强度的字符串
    public static String score(String in) {
        //总得分
        int score = scoreByLength(in) + scoreByDigit(in) + scoreByLetter(
                        in) + scoreByReward(in) + scoreBySgin(in);
        if (score < 25)
            return "VERY_WEAK";
        else if (score < 50)
            return "WEAK";
        else if (score < 60)
            return "AVERAGE";
        else if (score < 70)
            return "STRONG";
        else if (score < 80)
            return "VERY_STRONG";
        else if (score < 90)
            return "SECURE";
        else
            return "VERY_SECURE";
    }
}

发表于 2022-08-15 21:29:58 回复(0)
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        String password= scan.next();
        int score = 0;
        int len =password.length();
        if(len<=4){
            score+=5;
        }else if(len>=5&&len<=7){
            score+=10;
        }else if(len>=8){
            score+=25;
        }
        int number=0;
        int upper=0;
        int lower=0;
        int other =0;
        for(int i=0;i<len;i++){
            char ch = password.charAt(i);
            if(ch>='0'&&ch<='9'){
                number++;
            }else if(ch>='A'&&ch<='Z'){
                upper=1;
            }else if(ch>='a'&&ch<='z'){
                lower=1;
            }else{
                other++;
            }
        }
        if(number==1){
            score+=10;
        }else if(number>1){
            score+=20;
        }
        int word=upper+lower;
        if(word==1){
            score+=10;
        }else if(word>1){
            score+=20;
        }
        if(other==1){
            score+=10;
        }else if(other>1){
            score+=25;
        }
        if(word==2&&number>0&&other>0){
            score+=5;
        }else if(word==1&&number>0&&other>0){
            score+=3;
        }else if(word>0&&number>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{
            System.out.println("VERY_WEAK");
        }
        
    }
}

发表于 2022-06-25 00:13:29 回复(0)
import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    private static HashMap<Integer, String> levelHashMap = new HashMap<>();
    static {
        levelHashMap.put(90, "VERY_SECURE");
        levelHashMap.put(80, "SECURE");
        levelHashMap.put(70, "VERY_STRONG");
        levelHashMap.put(60, "STRONG");
        levelHashMap.put(50, "AVERAGE");
        levelHashMap.put(25, "WEAK");
        levelHashMap.put(0, "VERY_WEAK");
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String nextLine = scanner.nextLine();
        int length = nextLine.length();
        int[] intArrys = new int[4];
        int scoreSum = 0;
        // 一、密码长度:
        if (length <= 4) {
            scoreSum += 5;
        } else if (length >= 5 && length <= 7) {
            scoreSum += 10;
        } else if (length >= 8) {
            scoreSum += 25;
        }

        for (int i = 0; i < length; i++) {
            char charAt = nextLine.charAt(i);
            if (charAt >= '0' && charAt <= '9') {
                intArrys[0]++;
                continue;
            }
            if (charAt >= 'a' && charAt <= 'z') {
                intArrys[1]++;
                continue;
            }
            if (charAt >= 'A' && charAt <= 'Z') {
                intArrys[2]++;
                continue;
            }
            if ((charAt >= 0x21 && charAt <= 0x2F) || (charAt >= 0x3A && charAt <= 0x40)
                    || (charAt >= 0x5B && charAt <= 0x60) || (charAt >= 0x7B && charAt <= 0x7E)) {
                intArrys[3]++;
                continue;
            }
        }
        // 二、字母:
        if (intArrys[1] > 0 && intArrys[2] > 0) {
            scoreSum += 20;
        } else if (intArrys[1] > 0 || intArrys[2] > 0) {
            scoreSum += 10;
        } else if (intArrys[1] == 0 && intArrys[2] == 0) {
            scoreSum += 0;
        }
        if (intArrys[0] > 1) {
            scoreSum += 20;
        } else if (intArrys[0] == 1) {
            scoreSum += 10;
        } else {
            scoreSum += 0;
        }
        if (intArrys[3] > 1) {
            scoreSum += 25;
        } else if (intArrys[3] == 1) {
            scoreSum += 10;
        } else {
            scoreSum += 0;
        }
        if (intArrys[0] >= 1 && intArrys[1] >= 1 && intArrys[2] >= 1 && intArrys[3] >= 1) {
            scoreSum += 5;
        } else if (intArrys[0] >= 1 && intArrys[3] >= 1 && (intArrys[1] >= 1 || intArrys[2] >= 1)) {
            scoreSum += 3;
        } else if (intArrys[0] >= 1 && (intArrys[1] >= 1 || intArrys[2] >= 1)) {
            scoreSum += 2;
        }

        if (scoreSum >= 90) {
            System.out.println(levelHashMap.get(90));
        } else if (scoreSum >= 80) {
            System.out.println(levelHashMap.get(80));
        } else if (scoreSum >= 70) {
            System.out.println(levelHashMap.get(70));
        } else if (scoreSum >= 60) {
            System.out.println(levelHashMap.get(60));
        } else if (scoreSum >= 50) {
            System.out.println(levelHashMap.get(50));
        } else if (scoreSum >= 25) {
            System.out.println(levelHashMap.get(25));
        } else if (scoreSum >= 0) {
            System.out.println(levelHashMap.get(0));
        }
    }
}
发表于 2022-06-17 11:24:18 回复(0)
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
       String str = in.nextLine();
//         String str = "Jl)M:+";
        //得分计数
        int score = 0;
        int upletter = 0;
        int lowletter = 0;
        int num = 0;
        int symbol = 0;
        for (String s : str.split("")) {
            if (s.matches("[A-Z]")) upletter++;
            if (s.matches("[a-z]")) lowletter++;
            if (s.matches("[0-9]")) num++;
        }
        symbol = str.length() - upletter - lowletter - num;
        //长度得分
        if (str.length() >= 8) {
            score += 25;
        } else if (str.length() >= 4 && str.length() <= 7) {
            score += 10;
        } else if (str.length() <= 4) {
            score += 5;
        }

        //字母得分
        if (upletter > 0 && lowletter > 0) {
            score += 20;
        } else if ((upletter > 0 && lowletter == 0)||(upletter == 0 && lowletter > 0)) {
            score += 10;
        } else if (upletter == 0 && lowletter == 0) {
            score += 0;
        }

        //数字得分
        if (num > 1) {
            score += 20;
        } else if (num == 1) {
            score += 10;
        } else {
            score += 0;
        }

        //符合得分
        if (symbol > 1) {
            score += 25;
        } else if (symbol == 1) {
            score += 10;
        } else {
            score += 0;
        }

        //奖励得分
        if (upletter > 0 && lowletter > 0 && num > 0 && symbol > 1) {
            score += 5;
        } else if ((upletter + lowletter) > 0 && num > 0 && symbol > 1) {
            score += 3;
        } else if ((upletter + lowletter) > 0 && num > 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");
        }

    }
}
发表于 2022-05-24 10:27:52 回复(0)
正则表达式看变化
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        if ((getSymbolScore(str) + getNumberScore(str)  + getLength(str) + getLengthAph(str))+ getKindScore(str) >=90) {
            System.out.print("VERY_SECURE");
            return;
        }
        if ((getSymbolScore(str) + getNumberScore(str)  + getLength(str) + getLengthAph(str))+ getKindScore(str) >=80) {
            System.out.print("SECURE");
            return;
        }
        if ((getSymbolScore(str) + getNumberScore(str)  + getLength(str) + getLengthAph(str))+ getKindScore(str) >=70) {
            System.out.print("VERY_STRONG");
            return;
        }
        if ((getSymbolScore(str) + getNumberScore(str)  + getLength(str) + getLengthAph(str))+ getKindScore(str) >=60) {
            System.out.print("STRONG");
            return;
        }
        if ((getSymbolScore(str) + getNumberScore(str)  + getLength(str) + getLengthAph(str))+ getKindScore(str) >=50) {
            System.out.print("AVERAGE");
            return;
        }
        if ((getSymbolScore(str) + getNumberScore(str)  + getLength(str) + getLengthAph(str))+ getKindScore(str) >=25) {
            System.out.print("WEAK");
            return;
        }
        if ((getSymbolScore(str) + getNumberScore(str)  + getLength(str) + getLengthAph(str))+ getKindScore(str) >=0) {
            System.out.print("VERY_WEAK");
            return;
        }
    }

    public static int getLength(String str) {
        int score = 0;
        if (str.length() <= 4) {
            score += 5;
        } else if (str.length() >= 5 && str.length() <= 7) {
            score += 10;
        } else {
            score += 25;
        }
        return score;
    }

    public static int getLengthAph(String str) {
        int score = 0;
        String regex = "[a-z]";
        String regex2 = "[A-Z]";
        String s1 = str.replaceAll(regex, "");
        if (str.length() > s1.length()) {
            score += 10;
        }
        String s2 = str.replaceAll(regex2, "");
        if (str.length() > s2.length()) {
            score += 10;
        }
        return score;
    }

    public static int getNumberScore(String str) {
        int score = 0;
        String regex = "[0-9]";
        String s1 = str.replaceAll(regex, "");
        if (str.length() > s1.length()) {
            if (1 == (str.length() - s1.length())) {
                score += 10;
            } else {
                score += 20;
            }
        }
        return score;
    }

    public static int getSymbolScore(String str) {
        int score = 0;
        String regex = "[\\!\\\"#\\$%&'\\(\\)\\*\\+,-\\.\\/]";
        String regex2 = "[:;<=>\\?@]";
        String regex3 = "[\\[\\\\\\\\]\\^_` ]";
        String regex4 = "[{\\|}~]";
        String s1 = str.replaceAll(regex, "").replaceAll(regex2, "").replaceAll(regex3, "").replaceAll(regex4, "");
        if (str.length() > s1.length()) {
            if (1 == (str.length() - s1.length())) {
                score += 10;
            } else {
                score += 25;
            }
        }
        return score;
    }

    public static int getKindScore(String str) {
       if(getLengthAph(str) ==20 && getNumberScore(str) > 0 && getSymbolScore(str) > 0) {
           return 5;
       }
       if(getLengthAph(str) > 0 && getNumberScore(str) > 0 && getSymbolScore(str) > 0) {
           return 3;
       }
       if(getLengthAph(str) > 0 && getNumberScore(str) > 0 ) {
           return 2;
       }
       return 0;
    }
}




发表于 2022-05-10 19:10:01 回复(0)
import java.util.Scanner;


/**
 * 一、密码长度:
 * 5 分: 小于等于4 个字符
 * 10 分: 5 到7 字符
 * 25 分: 大于等于8 个字符
 * 二、字母:
 * 0 分: 没有字母
 * 10 分: 密码里的字母全都是小(大)写字母
 * 20 分: 密码里的字母符合”大小写混合“
 * 三、数字:
 * 0 分: 没有数字
 * 10 分: 1 个数字
 * 20 分: 大于1 个数字
 * 四、符号:
 * 0 分: 没有符号
 * 10 分: 1 个符号
 * 25 分: 大于1 个符号
 * 五、奖励(只能选符合最多的那一种奖励):
 * 2 分: 字母和数字
 * 3 分: 字母、数字和符号
 * 5 分: 大小写字母、数字和符号
 *
 * 分析:
 * 1.写成4个方法吧,第5个条件不写成方法
 * 2.很简单,但是没必要写,很浪费时间
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();

        char[] arr = input.toCharArray();
        int lengthCore = getLengthCore(arr);
        int letterCore = getLetterCore(arr);
        int digitCore = getDigitCore(arr);
        int symbolCore = getSymbolCore(arr);
        int awardScore = getAwardScore(letterCore, digitCore, symbolCore);

        int score = lengthCore+letterCore+digitCore+symbolCore+awardScore;
        String translate = translate(score);
        System.out.println(translate);


    }

    public static String translate(int score){
        if (score>=90) {
            return "VERY_SECURE";
        }else if(score>=80){
            return "SECURE";
        }else if(score>=70){
            return "VERY_STRONG";
        }else if(score>=60){
            return "STRONG";
        }else if(score>=50){
            return "AVERAGE";
        }else if(score>=25){
            return "WEAK";
        }

        return "VERY_WEAK";
    }


    public static int getLengthCore(char[] arr){
        if (arr.length >= 8) {
            return 25;
        }else if(arr.length>=5){
            return 10;
        }else{
            return 5;
        }
    }

    public static int getLetterCore(char[] arr){
        boolean upFlag = false;
        boolean lowFlag = false;
        for (char c : arr) {
            if (Character.isUpperCase(c)) {
                upFlag = true;
            }
            if (Character.isLowerCase(c)) {
                lowFlag =true;
            }

        }
        if(upFlag&&lowFlag){
            return 20;
        }else if(upFlag || lowFlag){
            return 10;
        }else{
            return 0;
        }
    }

    public static int getDigitCore(char[] arr){
        int digitCount = 0;
        for (char c : arr) {
            if (Character.isDigit(c)) {
                digitCount++;
            }
        }
        if(digitCount >= 2){
            return 20;
        }else if(digitCount == 1){
            return 10;
        }else{
            return 0;
        }
    }

    public static int getSymbolCore(char[] arr){
        int symbolCount = 0;
        for (char c : arr) {
            if (!Character.isLetterOrDigit(c)) {
                symbolCount++;
            }
        }
        if(symbolCount >= 2){
            return 25;
        }else if(symbolCount == 1){
            return 10;
        }else{
            return 0;
        }
    }

    public static int getAwardScore(int letterScore,int digitScore,int symbolScore){
        if(letterScore >0 && digitScore>0 && symbolScore>0){
            if(letterScore==20){
                return 5;
            }
            return 3;
        }
        if(letterScore >0 && digitScore>0){
            return 2;
        }
        return 0;
    }
}

发表于 2022-04-24 20:27:44 回复(0)
这题目确定不是出出来折磨人的吗
import java.util.Scanner;

public class Main{
    public static int lengthReward(String pw){
        int len = pw.length();
        
        if(len <= 4) return 5;
        else if(len >= 5 && len <= 7) return 10;
        else if(len >= 8) return 25;
        else return 0;
    }
    
    public static int alphabetReward(String pw){
        int len = pw.length();
        int len1 = pw.replaceAll("[A-Z]", "").length(); // 小写字母
        int len2 = pw.replaceAll("[a-z]", "").length(); // 大写字母
        
        if(len == len1 && len == len2) return 0;
        else if(len != len1 && len != len2) return 20;
        else return 10;
    }
    
    public static int digitReward(String pw){
        int len = pw.length();
        int len1 = pw.replaceAll("[0-9]", "").length();
        
        if(len - len1 == 0) return 0;
        else if(len - len1 == 1) return 10;
        else return 20;
    }
    
    public static int symbolReward(String pw){
        int len = pw.length();
        int len1 = pw.replaceAll("[^a-zA-Z0-9]", "").length();
        
        if(len - len1 == 0) return 0;
        else if(len - len1 == 1) return 10;
        else return 25;
    }
    
    public static int combineReward(String pw){
        int len = pw.length();
        int len1 = pw.replaceAll("[0-9]", "").length(); // 数字
        int len2 = pw.replaceAll("[A-Z]", "").length(); // 大写字母
        int len3 = pw.replaceAll("[a-z]", "").length(); // 小写字母
        int len4 = pw.replaceAll("[^0-9a-zA-Z]", "").length(); // 符号
        
        if(len-len1!=0 && len-len2!=0 && len-len3!=0 && len-len4!=0) return 5;
        else if(len-len1!=0 && len-len4!=0 &&
                (len-len2!=0 && len-len3==0) &&
                (len-len2==0 && len-len3!=0)){
            return 3;
        }
        else if((len-len2!=0 || len-len3!=0) && len-len1!=0 && len-len4==0) return 2;
        else return 0;        
    }
    
    public static String finalLevel(int score){
        if(score >= 0 && score < 25) return "VERY_WEAK";
        else if(score >= 25 && score < 50) return "WEAK";
        else if(score >= 50 && score < 60) return "AVERAGE";
        else if(score >= 60 && score < 70) return "STRONG";
        else if(score >= 70 && score < 80) return "VERY_STRONG";
        else if(score >= 80 && score < 90) return "SECURE";
        else if(score >= 90) return "VERY_SECURE";
        else return "ERROR";
    }
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String inp = sc.nextLine();
        int score = lengthReward(inp) + alphabetReward(inp) + 
            digitReward(inp) + symbolReward(inp) + combineReward(inp);
        
//         System.out.println(lengthReward(inp));
//         System.out.println(alphabetReward(inp));
//         System.out.println(digitReward(inp));
//         System.out.println(symbolReward(inp));
//         System.out.println(combineReward(inp));
        
        System.out.println(finalLevel(score));
    }
}


发表于 2022-04-22 16:27:40 回复(0)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();

        //密码长度分值
        int lenScore = 0;
        if (str.length() <= 4) {
            lenScore = 5;
        } else if (str.length() <= 7) {
            lenScore = 10;
        } else {
            lenScore = 25;
        }

        //字母分值
        int letterScore = 0;
        //小写字母和大写字母个数
        int lowerNum = 0;
        int upperNum = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z'){
                lowerNum++;
            }else if(str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {
                upperNum++;
            }
        }
        if(lowerNum == 0 && upperNum == 0){
            letterScore = 0;
        }else if(lowerNum > 0 && upperNum > 0){
            letterScore = 20;
        }else{
            letterScore = 10;
        }
        
        //数字分值
        int numScore = 0;
        //数字个数
        int count = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) >= '0' && str.charAt(i) <= '9'){
                count++;
            }
        }
        if(count == 0){
            numScore = 0;
        }else if (count == 1){
            numScore = 10;
        }else{
            numScore = 20;
        }
        
        //符号分值
        int charScore = 0;
        //符号个数
        int charNum = 0;
        for (int i = 0; i < str.length(); i++) {
            if ((str.charAt(i) >= 0x21 && str.charAt(i) <= 0x2F) ||
                (str.charAt(i) >= 0x3A && str.charAt(i) <= 0x40) ||
                (str.charAt(i) >= 0x5B && str.charAt(i) <= 0x60) ||
                (str.charAt(i) >= 0x7B && str.charAt(i) <= 0x7E)){
                charNum++;
            }
        }
        if(charNum == 0){
            charScore = 0;
        }else if(charNum == 1){
            charScore = 10;
        }else{
            charScore = 25;
        }
        
        //奖励分值
        int rewardScore = 0;
        if((lowerNum > 0 && upperNum > 0) && count > 0 && charNum > 0){
            rewardScore = 5;
        }else if((lowerNum > 0 || upperNum > 0) && count > 0 && charNum > 0){
            rewardScore = 3;
        }else if((lowerNum > 0 || upperNum > 0) && count > 0){
            rewardScore = 2;
        }
        
        //总分值
        int score = lenScore + letterScore + numScore + charScore + rewardScore;
        //安全等级
        StringBuffer security = new StringBuffer();
        if(score >= 90){
            security.append("VERY_SECURE");
        }else if(score >= 80){
            security.append("SECURE");
        }else if(score >= 70){
            security.append("VERY_STRONG");
        }else if(score >= 60){
            security.append("STRONG");
        }else if(score >= 50){
            security.append("AVERAGE");
        }else if(score >= 25){
            security.append("WEAK");
        }else if(score >= 0){
            security.append("VERY_WEAK");
        }
        
        //输出安全等级
        System.out.println(security);
    }
}

发表于 2022-04-06 13:40:30 回复(0)
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextLine()) {
            String str = scan.nextLine();
            int sum = 0;
            int sum1 = getLen(str);
            int sum2 = getChar(str);
            int sum3 = getNum(str);
            int sum4 = getSym(str);
            if(sum2 == 20 && sum3 >= 1 && sum4 >= 1) {
                sum = sum1 + sum2 + sum3 + sum4 + 5;
            } else if(sum2 == 10 && sum3 >= 1 && sum4 >= 1) {
                sum = sum1 + sum2 + sum3 + sum4 + 3;
            } else if(sum2 == 10 && sum3 >= 1 && sum4 == 0) {
                sum = sum1 + sum2 + sum3 + sum4 + 2;
            } else {
                sum = sum1 + sum2 + sum3 + sum4;
            }
            if(sum >= 90) {
                System.out.println("VERY_SECURE");
            } else if(sum >= 80) {
                System.out.println("SECURE");
            } else if(sum >= 70) {
                System.out.println("VERY_STRONG");
            } else if(sum >= 60) {
                System.out.println("STRONG");
            } else if(sum >= 50) {
                System.out.println("AVERAGE");
            } else if(sum >= 25) {
                System.out.println("WEAK");
            } else if(sum >= 0) {
                System.out.println("VERY_WEAK");
            }
        }
    }
    public static int getLen(String str) {
        if(str.length() >= 8) {
            return 25;
        } else if(str.length() >= 5 && str.length() <=7) {
            return 10;
        } else if(str.length() <= 4) {
            return 5;
        }
        return 0;
    }
    public static int getChar(String str) {
        int small = 0;
        int big = 0;
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) >= 97 && str.charAt(i) <= 122) {
                small++;
            } else if(str.charAt(i) >= 65 && str.charAt(i) <= 90) {
                big++;
            }
        }
        if(big > 0 && small > 0) {
            return 20;
        } else if(big > 0 || small > 0) {
            return 10;
        } else {
            return 0;
        }
    }
    public static int getNum(String str) {
        int count = 0;
        for (int i = 0; i < str.length(); i++) {
            if(str.charAt(i) - '0' >= 0 && str.charAt(i) - '0' <= 9) {
                count++;
            }
        }
        if(count > 1) {
            return 20;
        } else if(count == 1) {
            return 10;
        } else {
            return 0;
        }
    }
    public static int getSym(String str) {
        int count = 0;
        for (int i = 0; i < str.length(); i++) {
            if(!(str.charAt(i) >= 97 && str.charAt(i) <= 122) &&
                    !(str.charAt(i) >= 65 && str.charAt(i) <= 90) &&
                    !(str.charAt(i) - '0' >= 0 && str.charAt(i) - '0' <= 9)) {
                count++;
            }
        }
        if(count > 1) {
            return 25;
        } else if(count == 1) {
            return 10;
        } else {
            return 0;
        }
    }
}
发表于 2022-04-05 15:28:09 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);


        while (sc.hasNext()) {
            String password = sc.next();
            int count = 0;
            int sum_d=0,sum_o=0;
            boolean l_h=false,l_l=false;
            if(password.length()<=4){
                count+=5;
            }else if(password.length()>=5&&password.length()<=7){
                count+=10;
            }else{
                count+=25;
            }
            for(int i =0;i<password.length();i++){
                char c = password.charAt(i);
                if(Character.isLetter(c)){
                    if(Character.isUpperCase(c)){
                        l_h=true;
                    }
                    if(Character.isLowerCase(c)){
                        l_l=true;
                    }

                }else if(Character.isDigit(c)){
                    sum_d++;
                }else if(!Character.isLetter(c)&&!Character.isDigit(c)){
                    sum_o++;
                }
            }
            if(sum_d==1){
                count+=10;
            }else if(sum_d>1){
                count+=20;
            }
            if(sum_o==1){
                count+=10;
            }else if(sum_o>1){
                count+=25;
            }
            if(l_h&&l_l){
                count+=20;
            }else if(l_h||l_l){
                count+=10;
            }
            if(sum_d>0&&(l_h&&l_l)&&sum_o>0){
                count+=5;
            } else if(sum_d>0&&(l_h||l_l)){
                count+=2;
            }else if(sum_d>0&&(l_h||l_l)&&sum_o>0){
                count+=3;
            }
                solution(count);
        }

    }

    private static void solution(int count) {
            if(count>=90){
                System.out.println("VERY_SECURE");
            }else if(count>=80&&count<90){
                System.out.println("SECURE");
            }else if(count>=70&&count<80){
                System.out.println("VERY_STRONG");
            }else if(count>=60&&count<70){
                System.out.println("STRONG");
            }else if(count>=50&&count<60){
                System.out.println("AVERAGE");
            }else if(count>=25&&count<50){
                System.out.println("WEAK");
            }else if(count>=0&&count<25){
                System.out.println("VERY_WEAK");
            }
    }
}

发表于 2022-03-29 17:02:25 回复(0)


import java.util.Scanner;

/**
 * TODO
 */
public class Main {


    public static void main(String[] args) {
        int sum = 0;
        Scanner scanner = new Scanner(System.in);
        String result = scanner.nextLine();
        char[] chars = result.toCharArray();
        int checkLengthScore = checkLength(chars);
        int checkZiMuScore = checkZiMu(chars);
        int checkSuZhiScore = checkSuZhi(chars);
        int checkCharacterScore = checkCharacter(chars);
        if (checkSuZhiScore >=10 && checkZiMuScore >=20 && ( checkCharacterScore) >= 10) {
            sum = sum + 5;
        }else if (checkSuZhiScore >=10 && checkZiMuScore >=10 && ( checkCharacterScore) >= 10) {
             sum = sum + 3;
         }else if (checkSuZhiScore >=10 && checkZiMuScore >=10 && checkCharacterScore ==0) {
             sum = sum + 2;
         }
        sum = sum + checkLengthScore + checkZiMuScore + checkSuZhiScore + checkCharacterScore;
        System.out.println(getCheckResult(sum));
    }


    private static String getCheckResult(int sum) {
        if (sum >= 90) {
            return "VERY_SECURE";
        }
        if (sum >= 80) {
            return "SECURE";
        }
        if (sum >= 70) {
            return "VERY_STRONG";
        }
        if (sum >= 60) {
            return "STRONG";
        }
        if (sum >= 50) {
            return "AVERAGE";
        }
        if (sum >= 25) {
            return "WEAK";
        } else {
            return "VERY_WEAK";
        }
    }

    private static int checkLength(char[] chars) {
        int length = chars.length;
        if (length <= 4) {
            return 5;
        } else if (length <= 7) {
            return 10;
        } else {
            return 25;
        }
    }

    private static int checkZiMu(char[] chars) {
        int xXie = 0;
        int dXie = 0;
        int no = 0;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] >= 'a' && chars[i] <= 'z') {
                xXie++;
            } else if (chars[i] >= 'A' && chars[i] <= 'Z') {
                dXie++;
            } else {
                no++;
            }
        }
        int length = chars.length;
        if ((no - length) == 0) {
            return 0;
        } else if (((dXie) == 0) || ((xXie) == 0)) {
            return 10;
        } else if ((dXie > 0) || xXie > 0) {
            return 20;
        }
        return 0;
    }


    private static int checkSuZhi(char[] chars) {
        int xXie = 0;
        int no = 0;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] >= '0' && chars[i] <= '9') {
                xXie++;
            } else {
                no++;
            }
        }
        if ((no) == 0) {
            return 0;
        } else if (xXie == 1) {
            return 10;
        } else if (xXie > 1) {
            return 20;
        }
        return 0;
    }


    private static int checkCharacter(char[] chars) {
        int xXie = 0;
        int no = 0;
        for (int i = 0; i < chars.length; i++) {
            if (!(chars[i] >= '0' && chars[i] <= '9') &&
                    !(chars[i] >= 'A' && chars[i] <= 'Z') &&
                    !(chars[i] >= 'a' && chars[i] <= 'z')) {
                xXie++;
            } else {
                no++;
            }
        }
        if ((no) == 0) {
            return 0;
        } else if (xXie == 1) {
            return 10;
        } else if (xXie > 1) {
            return 25;
        }
        return 0;
    }

}

发表于 2022-03-28 22:26:16 回复(0)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.nextLine();
            System.out.println(solution(s));
        }
    }

    private static String solution(String s) {
        int grade = 0;
        int lenGrade = s.length();
        int lowerCase = 0;
        int upperCase = 0;
        int number = 0;
        int other = 0;
        if (lenGrade <= 4) {
            grade += 5;
        } else if (lenGrade < 8) {
            grade += 10;
        } else {
            grade += 25;
        }
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') {
                lowerCase++;
            } else if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') {
                upperCase++;
            } else if (s.charAt(i) >= '0' && s.charAt(i) <= '9') {
                number++;
            } else {
                other++;
            }
        }
        if ((lowerCase > 0 && upperCase == 0) || (lowerCase == 0 && upperCase > 0)) {
            grade += 10;
        } else if (lowerCase > 0 && upperCase > 0) {
            grade += 20;
        }
        if (number == 1) {
            grade += 10;
        } else if (number > 1) {
            grade += 20;
        }
        if (other == 1) {
            grade += 10;
        } else if (other > 1) {
            grade += 25;
        }
        if (lowerCase > 0 && upperCase > 0 && number > 0 && other > 0) {
            grade += 5;
        } else if (((lowerCase > 0 && upperCase == 0) || (upperCase > 0 && lowerCase == 0)) && number > 0 && other > 0) {
            grade += 3;
        } else if (((lowerCase > 0 && upperCase == 0) || (upperCase > 0 && lowerCase == 0)) && number > 0 && other == 0) {
            grade += 2;
        }
        if (grade >= 90) {
            return "VERY_SECURE";
        } else if (grade >= 80) {
            return "SECURE";
        } else if (grade >= 70) {
            return "VERY_STRONG";
        } else if (grade >= 60) {
            return "STRONG";
        } else if (grade >= 50) {
            return "AVERAGE";
        } else if (grade >= 25) {
            return "WEAK";
        } else {
            return "VERY_WEAK";
        }
    }
}

发表于 2022-03-27 23:02:00 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String in = scan.next();
        System.out.println(secure(in));
    }
    public static String secure(String in) {
        char[] arr = in.toCharArray();
        int score = 0;
        if (arr.length <= 4) {
            score += 5;
        } else if (arr.length <= 7) {
            score += 10;
        } else {
            score += 25;
        }
        int number = 0;
        int symbol = 0;
        boolean abc = false;
        boolean aflag = false;
        boolean Aflag = false;
        
        for (char c : arr) {
            if((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~')){
                symbol ++;
            }
            if(c >= '0' && c <= '9'){
                number ++;
            }
            if ((c >= 'a' && c <= 'z') || c >= 'A' && c <= 'Z'){
                abc = true;
                if(c >= 'a' && c <= 'z'){
                    aflag = true;
                }else{
                    Aflag = true;
                }
            }
        }
        boolean isLetterMix = aflag && Aflag;
        score += abc ? isLetterMix ? 20 : 10 : 0;
        score += number > 0 ? number == 1 ? 10 : 20 : 0;
        score += symbol > 0 ? symbol == 1 ? 10 : 25 : 0;
        score += (abc && number != 0 && symbol != 0 && isLetterMix) ? 5 : (abc && number != 0 && symbol != 0 && !isLetterMix) ? 3 : (abc && number != 0 && symbol == 0 && !isLetterMix) ? 2 : 0;
        if(score >= 90){
            return "VERY_SECURE";
        }else if(score >= 80){
            return "SECURE";
        }else if(score >= 70){
            return "VERY_STRONG";
        }else if(score >= 60){
            return "STRONG";
        }else if(score >= 50){
            return "AVERAGE";
        }else if(score >= 25){
            return "WEAK";
        }else{
            return "VERY_WEAK";
        }
    }
}

发表于 2022-03-24 06:22:12 回复(0)