题解 | #密码强度等级#

密码强度等级

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

#include <ctype.h>
#include <stdio.h>

int main() {
    int a, b,len,dand,num,el,more,all,danx,he;
    char str1[300];

     gets(str1);
     
        a=b=len=dand=num=el=more=all=danx=he=0;
        len=strlen(str1);
        if(len<=4) all=all+5;
        else if(len<=7&&len>=5) all=all+10;
        else if(len>=8) all=all+25;
        
        // printf("%d",all);
        for(a=0;a<len;a++)
        {
            if(isdigit(str1[a])) num++;
            if(isupper(str1[a]))
            dand++;
            if(islower(str1[a])) 
            danx++;
            if(ispunct(str1[a])) el++;
        }
      //  printf("%d",el);
        if(num==0) all=all; 
        else if(num==1)  all=all+10;
        else if(num>1)   all=all+20;   
       // printf("%d",all);
        if(dand==0&&danx==0) all=all; 
        else if(dand!=0&&danx==0)  all=all+10;
        else if(dand==0&&danx!=0)  all=all+10;//
        else if(dand!=0&&danx!=0) 
            {
            he++;
            all=all+20;
            }

        //printf("%d",all);
        if(el==0) all=all; 
        else if(el==1)  all=all+10;
        else if(el>1)   all=all+25;
       // printf("%d",all);

        if(num!=0&&he!=0&&el!=0) all=all+5;
        else if(num!=0&&dand==0&&danx!=0&&el!=0) all=all+3;
        else if(num!=0&&dand!=0&&danx==0&&el!=0) all=all+3;
        else if(num!=0&&dand==0&&danx!=0&&el==0) all=all+2;
        else if(num!=0&&dand!=0&&danx==0&&el==0) all=all+2;

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

    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
11-29 12:19
点赞 评论 收藏
分享
shtdbb_:还不错,没有让你做了笔试再挂你
点赞 评论 收藏
分享
牛客533433175号:更可气的是我做完这些给我拒了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务