题解 | #密码强度等级#

密码强度等级

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;
}

全部评论

相关推荐

秋盈丶:后续:我在宿舍群里和大学同学分享了这事儿,我好兄弟气不过把他挂到某脉上了,10w+阅读量几百条评论,直接干成精品贴子,爽
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务