题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include <stdio.h>
#include <string.h>
int main()
{
char secret[300];
while (scanf("%s", secret) != EOF)
{
int len, alpha = 0, bigalpha = 0, num = 0, sign = 0;
int grade = 0;
len = strlen(secret);
for (int i = 0; i < len; i++)
{
if (secret[i] >= '0' && secret[i] <= '9')
num++;
else if (secret[i] >= 'A' && secret[i] <= 'Z')
bigalpha = 1;
else if (secret[i] >= 'a' && secret[i] <= 'z')
alpha = 1;
else
sign++;
}
if (len <= 4)
grade += 5;
else if (len <= 7)
grade += 10;
else
grade += 25;
switch (alpha + bigalpha)
{
case 1:
grade += 10;
break;
case 2:
grade += 20;
break;
}
if (num == 1)
grade += 10;
else if (num > 1)
grade += 20;
if (sign == 1)
grade += 10;
else if (sign > 1)
grade += 25;
if (alpha && bigalpha && num && sign)
grade += 5;
else if (alpha + bigalpha && num && sign)
grade += 3;
else if (alpha + bigalpha && num)
grade += 2;
if (grade >= 90)
printf("VERY_SECURE\n");
else if (grade >= 80)
printf("SECURE\n");
else if (grade >= 70)
printf("VERY_STRONG\n");
else if (grade >= 60)
printf("STRONG\n");
else if (grade >= 50)
printf("AVERAGE\n");
else if (grade >= 25)
printf("WEAK\n");
else if (grade >= 0)
printf("VERY_WEAK\n");
}
return 0;
}