题解 | #密码强度等级#

密码强度等级

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

#include<stdio.h>
#include<string.h>
int main(){
    char str[301]={'\0'};
    int score1=0,score2=0,score3=0,score4=0,score5=0;
    int len=0,nw=0,nW=0,nd=0,ns=0;
    scanf("%[^\n]",str);
    //提取数量
    for(int i=0;i<strlen(str);i++){
        if(str[i]>='a'&&str[i]<='z')
            nw++;
        else if(str[i]>='A'&&str[i]<='Z')
            nW++;
        else if(str[i]>='0'&&str[i]<='9')
            nd++;
    }
    len=strlen(str);
    ns=len-nw-nW-nd;
    //1.密码长度
    if(len<=4)
        score1=5;
    else if(len>=5&&len<=7)
        score1=10;
    else score1=25;
    //2.字母
    if(nw==0&&nW==0)
        score2=0;
    else if(nw==0||nW==0)
        score2=10;
    else if(nw!=0&&nW!=0)
        score2=20;
    //3.数字
    if(nd==0)
        score3=0;
    else if(nd==1)
        score3=10;
    else score3=20;
    //4.符号
    if(ns==0)
        score4=0;
    else if(ns==1)
        score4=10;
    else score4=25;
    //5.奖励
    if(nw*nW*nd*ns!=0)
        score5=5;
    else if(nw*nd*ns!=0||nW*nd*ns!=0)
        score5=3;
    else if(nw*nd!=0||nW*nd!=0)
        score5=2;
    //总计
    int total;
    total=score1+score2+score3+score4+score5;
    switch(total/10){
        case 9:printf("VERY_SECURE");break;
        case 8:printf("SECURE");break;
        case 7:printf("VERY_STRONG");break;
        case 6:printf("STRONG");break;
        case 5:printf("AVERAGE");break;
    }
    if(total>=25&&total<50)
        printf("WEAK");
    else if(total>=0&&total<25)
        printf("VERY_WEAK");
}
全部评论

相关推荐

门口唉提是地铁杀:之前b站被一个游戏demo深深的吸引了。看up主页发现是个初创公司,而且还在招人,也是一天60。二面的时候要我做一个登录验证和传输文件两个微服务,做完要我推到github仓库,还要我加上jaeger和一堆运维工具做性能测试并且面试的时候投屏演示。我傻乎乎的做完以后人家跟我说一句现在暂时不招人,1分钱没拿到全是白干
你的秋招第一场笔试是哪家
点赞 评论 收藏
分享
06-12 16:23
已编辑
小米_软件开发(准入职员工)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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