题解 | #密码强度等级#

密码强度等级

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-18 18:37
门头沟学院 Java
点赞 评论 收藏
分享
06-12 16:00
天津大学 Java
牛客30236098...:腾讯坏事做尽,终面挂是最破防的 上次被挂了后我连简历都不刷了
点赞 评论 收藏
分享
07-17 12:09
门头沟学院 Java
讲的口干舌燥,头都晕了怎么要讲这么长啊
码农索隆:没事,你口干舌燥,他不一定会看,
投递小鹏汽车等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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