题解 | #密码强度等级#

密码强度等级

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

#include "stdio.h"
#include "string.h"
void print(int num)
{
    if(num>=90)      printf("VERY_SECURE\n");
    else if(num>=80) printf("SECURE\n");
        else if(num>=70) printf("VERY_STRONG\n");
            else if(num>=60) printf("STRONG\n");
                else if(num>=50) printf("AVERAGE\n");
                    else if(num>=25) printf("WEAK\n");
                        else if(num>=0) printf("VERY_WEAK\n");
                            }

int main()
{
    char buf[300];
    
     while(scanf("%s",buf)!=EOF)
    {
         char num = 0;
         int len = strlen(buf);
         char numb=0,llet=0,blet=0,fh=0;
         if(len>=8) num+=25;
         else if(len>=5 && len<=7) num+=10;
         else if(len<=4) num+=5;
         for(int i=0;i<len;i++)
         {
             if(buf[i]>='0' && buf[i]<='9') numb++;
             else if(buf[i]>='a' && buf[i]<='z') llet++;
             else if(buf[i]>='A' && buf[i]<='Z') blet++;
             else if(buf[i]>=0x21 && buf[i]<=0x2f) fh++;
             else if(buf[i]>=0x3a && buf[i]<=0x40) fh++;
             else if(buf[i]>=0x5b && buf[i]<=0x60) fh++;
             else if(buf[i]>=0x7b && buf[i]<=0x7e) fh++;
         }
         if(numb>1)num+=20;
         else if(numb==1) num+=10;
         
         if(fh>1)num+=25;
         else if(fh==1) num+=10;

         if(llet>=1 && blet>=1)num+=20;
         else if(llet>=1 || blet>=1) num+=10;
         
         if(llet>=1 && blet>=1 && fh>=1 && numb>=1)num+=5;
         else if((llet>=1 || blet>=1) && fh>=1 && numb>=1) num+=3;
         else if((llet>=1 || blet>=1) && numb>=1) num+=2;
         
         print(num);
         memset(buf, '\0', len);
    }
    return 0;
}

还是比较简单的题目, 主要就是逻辑弄清楚就很简单.

全部评论

相关推荐

评论
点赞
1
分享

创作者周榜

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