题解 | #密码强度等级#

密码强度等级

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

#include <stdio.h>
#include <string.h>

int main() {
    char str[305];
    int count=0;
    scanf("%s",str);
    int len=strlen(str);
    if(len<=4){
        count+=5;
    }
    else if(len<=7){
        count+=10;
    }
    else{
        count+=25;
    }
    int flag1_0=0,flag1_1=0;
    for(int i=0;str[i]!='\0';i++){
        if(str[i]>='a'&&str[i]<='z'){
            flag1_0=1;
            continue;
        }    
        if(str[i]>='A'&&str[i]<='Z'){
            flag1_1=1;
        }
    }
    if(flag1_0&&flag1_1){
        count+=20;
    }
    else if(flag1_0||flag1_1){
        count+=10;
    }
    int flag2=0,num2=0;
    for(int i=0;str[i]!='\0';i++){
        if(str[i]>='0'&&str[i]<='9'){
            flag2=1;
            num2++;
        }    
    }
    if(flag2){
        if(num2>1){
            count+=20;
        }
        else{
            count+=10;
        }
    }
    int flag3=0,num3=0;
    for(int i=0;str[i]!='\0';i++){
        if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')||(str[i]>='0'&&str[i]<='9')){
            continue;
        }
        else{
            flag3=1;
            num3++;
        }    
    }
    if(flag3){
        if(num3>1){
            count+=25;
        }
        else{
            count+=10;
        }
    }
    if(flag1_0&&flag1_1&&flag2&&flag3){
        count+=5;
    }
    else if((flag1_0||flag1_1)&&flag2&&flag3){
        count+=3;
    }
    else if((flag1_0||flag1_1)&&flag2){
        count+=2;
    }
    if(count>=90){
        printf("VERY_SECURE\n");
    }
    else if(count>=80){
        printf("SECURE\n");
    }
    else if(count>=70){
        printf("VERY_STRONG\n");
    }
    else if(count>=60){
        printf("STRONG\n");
    }
    else if(count>=50){
        printf("AVERAGE\n");
    }
    else if(count>=25){
        printf("WEAK\n");
    }
    else{
        printf("VERY_WEAK\n");
    }
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 18:02
好不容易拿到了字节Offer,鼠鼠做后端的,但家里人觉得可能被裁员不稳定,让鼠鼠去投国企,现在好纠结到底该咋选
文档传偷助手:该投就投吧,不过建议别放弃offer 拿到手里的才是最好的
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
真的很糟糕:欲哭无泪
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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