题解 | #密码强度等级#

密码强度等级

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

#include <stdio.h>
#include <string.h>
int main(void)
{
    char str[1000];
    while(scanf("%s",str)!=EOF)
    {
        int i,len;
        int sum=0;
        int xiaoxie=0,daxie=0,hunhe=0;
        int shuzi=0,fuhao=0;
        int zimu=0;
        len=strlen(str);
        if(len<=4)
        {
            sum=sum+5;
        }
        else if(len>4&&len<=7)
        {
            sum=sum+10;
        }
        else if(len>=8)
        {
            sum=sum+25;
        }
        for(i=0;i<len;i++)
        {
            if(str[i]<='z'&&str[i]>='a')
            {
                xiaoxie=1;
            }
            else if(str[i]<='Z'&&str[i]>='A')
            {
                daxie=1;
            }
            else if(str[i]>='0'&&str[i]<='9')
            {
                shuzi++;
            }
            else if((str[i]>='!' && str[i] <='/') || (str[i]>=':' && str[i] <='@') ||
                     (str[i]>='[' && str[i] <='`') || (str[i]>='{' && str[i] <='~'))
            {
                fuhao++;
            }
        }
        if(xiaoxie==1||daxie==1){
            zimu=1;
        }
        if(xiaoxie==0&&daxie==0){
            sum=sum+0;
        }
        else if((xiaoxie==1&&daxie==0)||(xiaoxie==0&&daxie==1)){
            sum=sum+10;
        }
        else if(xiaoxie==1&&daxie==1){
            sum=sum+20;
        }
        if(shuzi==0){
            sum=sum+0;
        }
        else if(shuzi==1){
            sum=sum+10;
        }
        else if(shuzi>1){
            sum=sum+20;
        }
        if(fuhao==0){
            sum=sum+0;
        }
        else if(fuhao==1){
            sum=sum+10;
        }
        else if(fuhao>1){
            sum=sum+25;
        }
        if(zimu==1&&shuzi>0&&fuhao==0){
            sum=sum+2;
        }
        else if((xiaoxie==1&&daxie==0&&shuzi>0&&fuhao>0)||(xiaoxie==0&&daxie==1&&shuzi>0&&fuhao>0)){
            sum=sum+3;
        }
        else if(daxie==1&&xiaoxie==1&&shuzi>0&&fuhao>0){
            sum=sum+5;
        }
        if(sum>=90){
            printf("VERY_SECURE\n");
        }
        else if(sum>=80&&sum<90){
            printf("SECURE\n");
        }
        else if(sum>=70&&sum<80){
            printf("VERY_STRONG\n");
        }
        else if(sum>=60&&sum<70){
            printf("STRONG\n");
        }
        else if(sum>=50&&sum<60){
            printf("AVERAGE\n");
        }
        else if(sum>=25&&sum<50){
            printf("WEAK\n");
        }
        else{
            printf("VERY_WEAK\n");
        }
        sum=0;
    }
}
全部评论

相关推荐

牛客5655:其他公司的面试(事)吗
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务