题目:密码强度等级
描述 | |
---|---|
知识点 | 枚举 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | 输入一个string的密码 |
输出 | 输出密码等级 |
样例输入 | 38$@NoNoNo |
样例输出 | VERY_SECURE |
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s;
cin>>s;
int len=0,ualp=0,lalp=0,dig=0,other=0,score=0;
len=s.size();
if(len<=4)
score+=5;
else if(len<=7)
score+=10;
else
score+=25;
for(int i=0;i<s.size();i++)
{
if(isupper(s[i]))
ualp++;
else if(islower(s[i]))
lalp++;
else if(isdigit(s[i]))
dig++;
else if(s[i]>=0x21&&s[i]<=0x2F||s[i]>=0x3A&&s[i]<=0x40||s[i]>=0x5B&&s[i]<=0x60||s[i]>=0x7B&&s[i]<=0x7E)
other++;
}
if(ualp!=0&&lalp==0||ualp==0&&lalp!=0)
score+=10;
else if(ualp!=0&&lalp!=0)
score+=20;
if(dig==1)
score+=10;
else if(dig>1)
score+=20;
if(other==1)
score+=10;
else if(other>1)
score+=25;
if(ualp&&lalp&&dig&&other)
score+=5;
else if(ualp+lalp!=0&&dig&&other)
score+=3;
else if(ualp+lalp!=0&&dig)
score+=2;
if(score>=90)
cout<<"VERY_SECURE"<<endl;
else if(score>=80)
cout<<"SECURE"<<endl;
else if(score>=70)
cout<<"VERY_STRONG"<<endl;
else if(score>=60)
cout<<"STRONG"<<endl;
else if(score>=50)
cout<<"AVERAGE"<<endl;
else if(score>=25)
cout<<"WEAK"<<endl;
else
cout<<"VERY_WEAK"<<endl;
//system("pause");
return 0;
}