题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include<stdio.h>
#include<string.h>
int main()
{
char arr[1000] = "";
scanf("%s", arr);
int grade = 0;
int len = strlen(arr);
int num = 0;
int zimu = 0;
int zimuupper = 0;
int zimulower = 0;
int fuhao = 0;
//长度
if (len <= 4)
grade += 5;
else if (len >= 5 && len <= 7)
grade += 10;
else
grade += 25;
//字母
int upper = 0;
int lower = 0;
for (int i = 0; i < len; i++)
{
if (arr[i] >= 'a' && arr[i] <= 'z')
{
lower++;
zimulower = 1;
}
else if (arr[i] >= 'A' && arr[i] <= 'Z')
{
upper++;
zimuupper = 1;
}
}
if (lower >= 1 && upper >= 1)
grade += 20;
else if (lower >= 1 || upper >= 1)
grade += 10;
else
zimu = 1;
//数字
int count = 0;
for (int i = 0; i < len; i++)
{
if (arr[i] >= '0' && arr[i] <= '9')
count++;
}
if (count == 0)
num = 1;
else if (count == 1)
grade += 10;
else
grade += 20;
//符号
int count1 = 0;
for (int i = 0; i < len; i++)
{
if ((arr[i] >= '!' && arr[i] <= '/') || (arr[i] >= ':' && arr[i] <= '@') || (arr[i] >= '[' && arr[i] <= '`') || (arr[i] >= '{' && arr[i] <= '~'))
count1++;
}
if (count1 == 0)
fuhao = 1;
else if (count1 == 1)
grade += 10;
else
grade += 25;
//奖励
if (zimu + fuhao + num == 0)
{
if (zimuupper + zimulower == 2)
grade += 5;
else
grade += 3;
}
else if (zimu + num == 0)
grade += 2;
//判断输出等级
if (grade >= 90)
printf("VERY_SECURE");
else if (grade >= 80)
printf("SECURE");
else if (grade >= 70)
printf("VERY_STRONG");
else if (grade >= 60)
printf("STRONG");
else if (grade >= 50)
printf("AVERAGE");
else if (grade >= 25)
printf("WEAK");
else
printf("VERY_WEAK");
return 0;
}
#include<string.h>
int main()
{
char arr[1000] = "";
scanf("%s", arr);
int grade = 0;
int len = strlen(arr);
int num = 0;
int zimu = 0;
int zimuupper = 0;
int zimulower = 0;
int fuhao = 0;
//长度
if (len <= 4)
grade += 5;
else if (len >= 5 && len <= 7)
grade += 10;
else
grade += 25;
//字母
int upper = 0;
int lower = 0;
for (int i = 0; i < len; i++)
{
if (arr[i] >= 'a' && arr[i] <= 'z')
{
lower++;
zimulower = 1;
}
else if (arr[i] >= 'A' && arr[i] <= 'Z')
{
upper++;
zimuupper = 1;
}
}
if (lower >= 1 && upper >= 1)
grade += 20;
else if (lower >= 1 || upper >= 1)
grade += 10;
else
zimu = 1;
//数字
int count = 0;
for (int i = 0; i < len; i++)
{
if (arr[i] >= '0' && arr[i] <= '9')
count++;
}
if (count == 0)
num = 1;
else if (count == 1)
grade += 10;
else
grade += 20;
//符号
int count1 = 0;
for (int i = 0; i < len; i++)
{
if ((arr[i] >= '!' && arr[i] <= '/') || (arr[i] >= ':' && arr[i] <= '@') || (arr[i] >= '[' && arr[i] <= '`') || (arr[i] >= '{' && arr[i] <= '~'))
count1++;
}
if (count1 == 0)
fuhao = 1;
else if (count1 == 1)
grade += 10;
else
grade += 25;
//奖励
if (zimu + fuhao + num == 0)
{
if (zimuupper + zimulower == 2)
grade += 5;
else
grade += 3;
}
else if (zimu + num == 0)
grade += 2;
//判断输出等级
if (grade >= 90)
printf("VERY_SECURE");
else if (grade >= 80)
printf("SECURE");
else if (grade >= 70)
printf("VERY_STRONG");
else if (grade >= 60)
printf("STRONG");
else if (grade >= 50)
printf("AVERAGE");
else if (grade >= 25)
printf("WEAK");
else
printf("VERY_WEAK");
return 0;
}