HJ87 密码强度等级

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        String s = sc.nextLine();
        String res = "";

        int score = 0;
        int c1 = 0;//数字
        int c2 = 0;//大写字母
        int c3 = 0;//小写字母
        int c4 = 0;//符号

        for (int i = 0; i < s.length(); i ++) {
            char c = s.charAt(i);
            if ( '0' <= c && c <= '9') c1++;
            else if ( 'A' <= c && c <= 'Z') c2++;
            else if ( 'a' <= c && c <= 'z') c3++;
            else c4++;
        }

        if (s.length() <= 4) {
            score += 5;
        } else if (s.length() <= 7) {
            score += 10;
        } else {
            score += 25;
        }

        if (c2 == 0 && c3 == 0 ) {
        } else if ((c2 == 0 && c3 != 0) || (c2 != 0 && c3 == 0)) {
            score += 10;
        } else {
            score += 20;
        }

        if (c1 <= 0) {
        } else if (c1 <= 1) {
            score += 10;
        } else {
            score += 20;
        }

        if (c4 <= 0) {
            score += 0;
        } else if (c4 <= 1) {
            score += 10;
        } else {
            score += 25;
        }

        if (c1 != 0 && c2 != 0 && c3 != 0 && c4 != 0) {
            score += 5;
        } else if ( (c1 != 0 && c2 == 0 && c3 != 0 && c4 != 0) ||
                    (c1 != 0 && c2 != 0 && c3 == 0 && c4 != 0) ) {
            score += 3;
        } else if (c1 != 0 && ( c2 != 0 || c3 != 0 ) && c4 == 0) {
            score += 2;
        }

        if(score >= 90) res = "VERY_SECURE";
        else if(score >= 80) res = "SECURE";
        else if(score >= 70) res = "VERY_STRONG";
        else if(score >= 60) res = "STRONG";
        else if(score >= 50) res = "AVERAGE";
        else if(score >= 25) res = "WEAK";
        else if(score >= 0)  res = "VERY_WEAK";

        System.out.println(res);

    }
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值