题解 | #密码强度等级#

密码强度等级

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

#include <stdio.h>

int main() {
    int n = 0;
    char s[300];
    gets(s);
    int len = strlen(s);
    if (len <= 4)n += 5;
    else if (len > 4 && len <= 7) n += 10;
    else n += 25;
    int a = 0, b = 0, c = 0, d = 0; //大小写,数字,符号
    for (int i = 0; i < len; i++) {
        if (s[i] >= 'A' && s[i] <= 'Z') a++;
        else if (s[i] >= 'a' && s[i] <= 'z') b++;
        else if (s[i] >= '0' && s[i] <= '9') c++;
        else d++;
    }

    if (a != 0) n += 10;
    if (b != 0) n += 10;
    if (c == 1) n += 10;
    else if (c > 1)n += 20;
    if (d == 1) n += 10;
    else if (d > 1)n += 25;    
    if(a!=0&&b!=0&&c!=0&&d!=0) n+=5;
    else if((a!=0||b!=0)&&c!=0&&d!=0) n+=3;
    else if((a!=0||b!=0)&&c!=0) n+=2;

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

    return 0;
}

全部评论

相关推荐

烤点老白薯:亲娘嘞🐶💩啊你的简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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