描述 | |
---|---|
知识点 | 枚举 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | 输入一个string的密码 |
输出 | 输出密码等级 |
样例输入 | 38$@NoNoNo |
样例输出 | VERY_SECURE |
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
getline(cin, str);
int score = 0;
int length = str.size();
if (length <= 4)
score += 5;
else if (length >= 5 && length <= 7)
score += 10;
else if (length >= 8)
score += 25;
int flag1 = 0, flag2 = 0;//计数器
int flag3 = 0;
int flag4 = 0;
for (int i = 0; i<length; i++) //字符统计
{
if (str[i] >= 'a' && str[i] <= 'z')
flag1++;
if (str[i] >= 'A' && str[i] <= 'Z')
flag2++;
if (str[i] >= '0' && str[i] <= '9')
flag3++;
if ((str[i] >= 0x21 && str[i] <= 0x2F) ||
(str[i] >= 0x3A && str[i] <= 0x40) ||
(str[i] >= 0x5B && str[i] <= 0x60) ||
(str[i] >= 0x7B &&str[i] <= 0x7E))
flag4++;
}
if (flag1 == 0 && flag2 == 0) //字母
score += 0;
else if ((flag1 != 0 && flag2 == 0) || (flag1 == 0 && flag2 != 0))
score += 10;
else if (flag1 != 0 && flag2 != 0)
score += 20;
if (flag3 == 0) //数字
score += 0;
else if (flag3 == 1)
score += 10;
else if (flag3>1)
score += 20;
if (flag4 == 0) //符号
score += 0;
else if (flag4 == 1)
score += 10;
else if (flag4>1)
score += 25;
if ((flag1 != 0 && flag2 != 0) && flag3 != 0 && flag4 != 0)
score += 5;
else if (((flag1 != 0 && flag2 == 0) || (flag1 == 0 && flag2 != 0)) && flag3 != 0 && flag4 != 0)
score += 3;
else if (flag4 == 0 && flag3 != 0 &&
((flag1 != 0 && flag2 == 0) || (flag1 == 0 && flag2 != 0)))
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;
return 0;
}
这题就用的枚举法,写得很傻,而且中间计分时想偷懒对特殊字符直接用一个大区间0x21~0x7E还通不过,一定要分区间写成或语句并列判断才AC.
最后奖励计分那里注意满分就是95,不是叠加奖励的。