题解 | #密码强度等级#

密码强度等级

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

#include<iostream>
using namespace std;
int main()
{
    string s;
    while(cin>>s)
    {
        int len=s.length();
        int minch=0;
        int maxch=0;
        int digit=0;
        int other=0;
        int i=0;
        while(s[i]!='\0')
        {
            if(s[i]>='0'&&s[i]<='9')digit++;
            else if(s[i]>='a'&&s[i]<='z')minch++;
            else if(s[i]>='A'&&s[i]<='Z')maxch++;
            else other++;
            i++;
        }
        int score=0;
        if(len<=4)score+=5;
        else if(len>=5&&len<=7)score+=10;
        else score+=25;
        
        if((minch>0&&maxch==0)||(minch==0&&maxch>0))score+=10;
        else if(minch>0&&maxch>0)score+=20;
        
        if(digit==1)
        {
            score+=10;
        }
        else if(digit>1)
        {
            score+=20;
        }
        if(other==1)
        {
            score+=10;
        }
        else if(other>1)
        {
            score+=25;
        }
        if(minch>0&&maxch>0&&digit>0&&other>0)
        {
            score+=5;
        }
        else if((minch>0||maxch>0)&&digit>0&&other>0)
        {
            score+=3;
        }
        else if(minch>0&&maxch>0&&digit>0&&other==0)
        {
            score+=2;
        }
        string res;
        if(score>=90)res="VERY_SECURE";
        else if(score>=80)res="SECURE";
        else if(score>=70)res="VERY_STRONG";
        else if(score>=60)res="STRONG";
        else if(score>=50)res="AVERAGE";
        else if(score>=25)res="WEAK";
        else if(score>=0)res="VERY_WEAK";
        cout<<res<<endl;
    }
    return 0;
}
全部评论

相关推荐

10-14 10:56
已编辑
长沙学院 嵌入式软件开发
痴心的00后拿到了ssp:hr面挂了,无所谓了反正不去😃
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
10-15 14:22
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务