描述

密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。

一、密码长度:
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分。

代码部分:
#include <stdio.h>
#include <string.h>
//以下是Senky的代码:
int score = 0; //分数
int len = 0; //长度
int alp_small = 0; //小写字母标记
int alp_big = 0; //大写字母标记
int num_count = 0; //数字个数计数器
int cha_count = 0; //字符个数计数器
void Judge_len(char pwd[]) {
    if (len <= 4) score += 5;
    else if (len >= 5 && len <= 7) score += 10;
    else  score += 25;
    //printf("len后%d\n", score);
}

void Judge_alp(char pwd[]) {
    for (int i = 0; i < len; i++) {
        if (pwd[i] >= 'a' && pwd[i] <= 'z') {
            alp_small++; //有小写字母
        } else if (pwd[i] >= 'A' && pwd[i] <= 'Z') {
            alp_big++; //有大写字母
        }
    }
    if (alp_small && alp_big) score += 20; //大小写混合
    else if (alp_small || alp_big) score += 10; //只有大小写
    else score += 0;
    //printf("alp后%d\n", score);
}

void Judge_num(char pwd[]) {
    for (int i = 0; i < len; i++) {
        if (pwd[i] >= '0' && pwd[i] <= '9') {
            num_count++;
        }
    }
    if (num_count > 1) score += 20;//大于一个数字
    else if (1 == num_count) score += 10; //只有一个数字
    //printf("num后%d\n", score);
}

void Judge_cha(char pwd[]) {
    for (int i = 0; i < len; i++) {
        if (
                (pwd[i] >= '!' && pwd[i] <= '/') || 
                (pwd[i] >= ':' && pwd[i] <= '@') || 
                (pwd[i] >= '[' && pwd[i] <= '`') || 
                (pwd[i] >= '{' && pwd[i] <= '~')
           )
            cha_count++;//如果是字符,字符计数器++
    }
    if (cha_count > 1) score += 25;
    else if (1 == cha_count) score += 10;
    //printf("cha后%d\n", score);
}

void reward() {
    if (alp_small && alp_big && num_count &&
            cha_count) score += 5;//大小写字母、数字和符号
    else if ((alp_small || alp_big) && num_count &&
             cha_count) score += 3;//字母、数字和符号
    else if ((alp_small || alp_big) && num_count) score += 2;//字母和数字
    //printf("reward后%d\n", score);
}

void Judge_final() {
    if (score >= 90) printf("VERY_SECURE");
    else if (score >= 80) printf("SECURE");
    else if (score >= 70) printf("VERY_STRONG");
    else if (score >= 60) printf("STRONG");
    else if (score >= 50) printf("AVERAGE");
    else if (score >= 25) printf("WEAK");
    else if (score >= 0) printf("VERY_WEAK");
}

int main() {
    char pwd[300];//密码长度最多300
    scanf("%[^\n]", pwd);//从缓存区读入pwd
    len=(int)strlen(pwd);//计算密码的长度(VS会报错,strlen返回unsigned_int64)
    Judge_len(pwd);//长度评分
    Judge_alp(pwd);//字母评分
    Judge_num(pwd);//数字评分
    Judge_cha(pwd);//字符评分
    reward();//奖励得分
    Judge_final();//最后评分标准
    return 0;//编辑于2022/10/11
}
总结
①   这是最近HJ中目前比较高内聚低耦合的题目了  
   当前帖子仅供自我精进、学习使用,有不足之处欢迎指正;