题解 | 密码强度等级

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNextLine()) {
            char[] c = in.nextLine().toCharArray();
            int count = 0;
            if (c.length <= 5) count += 5;
            if (c.length > 5 && c.length <= 7) count += 10;
            if (c.length >= 8) count += 25;

// System.out.println(c.length);
            int uc = 0;
            int lc = 0;
            int nu = 0;
            int sig = 0;
            for (int i = 0; i < c.length; i++) {
                if (Character.isUpperCase(c[i])) {
                    uc++;
                } else if (Character.isLowerCase(c[i])) {
                    lc++;
                } else if (Character.isDigit(c[i])) {
                    nu++;
                } else {
                    sig++;
                }
            }
            //      System.out.println(uc+" "+lc+" "+nu+" "+sig);
            if (uc == 0 && lc == 0) {
                count += 0;
            } else if ((uc > 0 && lc == 0) || (uc == 0 && lc > 0)) {
                count += 10;
            } else {
                count += 20;
            }

            if (nu == 0) {
                count += 0;
            } else if (nu == 1) {
                count += 10;
            } else {
                count += 20;
            }

            if (sig == 0) {
                count += 0;
            } else if (sig == 1) {
                count += 10;
            } else {
                count += 25;
            }
            if (uc + lc > 0 && nu > 0 && sig == 0) {
                count += 2;
            } else if ((uc > 0 && nu > 0 && sig > 0 && lc == 0) || (lc > 0 && nu > 0 &&
                       sig < 0 || uc == 0)) {
                count += 3;
            } else if (uc > 0 && lc > 0 && nu > 0 && sig > 0) {
                count += 5;
            } else {
                count += 0;
            }

            if (count >= 90) System.out.println("VERY_SECURE");
            if (count >= 80 && count < 90) System.out.println("SECURE");
            if (count >= 70 && count < 80) System.out.println("VERY_STRONG");
            if (count >= 60 && count < 70) System.out.println("STRONG");
            if (count >= 50 && count < 60) System.out.println("AVERAGE");
            if (count >= 25 && count < 50) System.out.println("WEAK");
            if (count >= 0 && count < 25) System.out.println("VERY_WEAK");

        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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