题解 | #密码强度等级#

密码强度等级

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

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

int main() {
    char*str = (char*)malloc(sizeof(char)*300);
    int numcount = 0;
    int smalletter=0,bigletter = 0;
    int symble = 0;
    int goal = 0;
    while(~scanf("%s",str))
    {
        int len = strlen(str);
        
        if(len <=4)
        {
            goal+=5;
        }else if (len>=5&&len<=7) {
            goal+=10;
        }else{
            goal+=25;
        }

        for(int i=0;i<len;i++)
        {
            if(str[i]<='z'&&str[i]>='a')
            {
                smalletter = 1;
            }else if(str[i]<='Z'&&str[i]>='A')
            {
                bigletter = 1;
            }else if(str[i]<='9'&&str[i]>='0')
            {
                numcount++;
            }else 
            {
                symble++;
            }
            if(symble==2 && smalletter && bigletter && numcount == 2)
            {
                break;
            }
        }

        if(smalletter && bigletter)
        {
            goal+=20;
        }else if(smalletter || bigletter)
        {
            goal+=10;
        }

        if(numcount >= 2)
        {
            goal+=20;
        }else if(numcount == 1)
        {
            goal+=10;
        }

        if(symble >= 2)
        {
            goal+=25;
        }else if(symble == 1)
        {
            goal+=10;
        }

        if(symble && numcount && bigletter&&smalletter)
        {
            goal +=5;
        }else if(symble && numcount &&(bigletter || smalletter))
        {
            goal +=3;
        }else if(symble && numcount)
        {
            goal +=2;
        }

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

全部评论

相关推荐

面了100年面试不知...:今年白菜这么多,冬天可以狂吃了
点赞 评论 收藏
分享
10-31 22:23
门头沟学院 Java
天然不是卷王:太好了 佬的金九银十结束,等offer吐出来,我的金11银12就要开始了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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