题解 | #密码强度等级#
密码强度等级
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;
}