题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
string str=Console.ReadLine();
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
int sum4 = 0;
int sum5 = 0;
//密码长度
if(str.Length<=4)
{
sum1 = 5;
}
else if(str.Length>=8)
{
sum1 = 25;
}
else
{
sum1 = 10;
}
//字母
int flag1 = 0;
int flag2 = 0;
for(int i=0;i<str.Length;i++)
{
if(str[i]>='a'&&str[i]<='z')
{
flag1 = 1;
}
if (str[i] >= 'A' && str[i] <= 'Z')
{
flag2 = 1;
}
}
int flag3 = flag1 + flag2;
if (flag3==0)
{
sum2 = 0;
}
else if(flag3==1)//有字母
{
sum2 = 10;
}
else//有大小写字母
{
sum2 = 20;
}
//数字
int num = 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] >= '0' && str[i] <= '9')
{
num++;
}
}
if (num == 0)
{
sum3 = 0;
}
else if (num == 1)//有数字
{
sum3 = 10;
}
else
{
sum3 = 20;
}
//符号
int num2 = 0;
for (int i = 0; i < str.Length; i++)
{
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))
{
num2++;
}
}
if (num2 == 0)
{
sum4 = 0;
}
else if (num2 == 1)//有符号
{
sum4 = 10;
}
else
{
sum4 = 25;
}
//奖励
if(flag3>=1&&num>=1&&num2==0)
{
sum5 = 2;
}
else if(flag3>=1&&flag3<2&&num>=1&&num2>=1)
{
sum5 = 3;
}
else if(flag3>=2&&num>=1&&num2>=1)
{
sum5 = 5;
}
//总分
int sum = sum1 + sum2 + sum3 + sum4 + sum5;
if (sum<25)
{
Console.WriteLine("VERY_WEAK");
}
else if(sum>=25&&sum<50)
{
Console.WriteLine("WEAK");
}
else if (sum >= 50 && sum < 60)
{
Console.WriteLine("AVERAGE");
}
else if (sum >= 60 && sum < 70)
{
Console.WriteLine("STRONG");
}
else if (sum >= 70 && sum < 80)
{
Console.WriteLine("VERY_STRONG");
}
else if (sum >= 80 && sum < 90)
{
Console.WriteLine("SECURE");
}
else if (sum >= 90)
{
Console.WriteLine("VERY_SECURE");
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
string str=Console.ReadLine();
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
int sum4 = 0;
int sum5 = 0;
//密码长度
if(str.Length<=4)
{
sum1 = 5;
}
else if(str.Length>=8)
{
sum1 = 25;
}
else
{
sum1 = 10;
}
//字母
int flag1 = 0;
int flag2 = 0;
for(int i=0;i<str.Length;i++)
{
if(str[i]>='a'&&str[i]<='z')
{
flag1 = 1;
}
if (str[i] >= 'A' && str[i] <= 'Z')
{
flag2 = 1;
}
}
int flag3 = flag1 + flag2;
if (flag3==0)
{
sum2 = 0;
}
else if(flag3==1)//有字母
{
sum2 = 10;
}
else//有大小写字母
{
sum2 = 20;
}
//数字
int num = 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] >= '0' && str[i] <= '9')
{
num++;
}
}
if (num == 0)
{
sum3 = 0;
}
else if (num == 1)//有数字
{
sum3 = 10;
}
else
{
sum3 = 20;
}
//符号
int num2 = 0;
for (int i = 0; i < str.Length; i++)
{
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))
{
num2++;
}
}
if (num2 == 0)
{
sum4 = 0;
}
else if (num2 == 1)//有符号
{
sum4 = 10;
}
else
{
sum4 = 25;
}
//奖励
if(flag3>=1&&num>=1&&num2==0)
{
sum5 = 2;
}
else if(flag3>=1&&flag3<2&&num>=1&&num2>=1)
{
sum5 = 3;
}
else if(flag3>=2&&num>=1&&num2>=1)
{
sum5 = 5;
}
//总分
int sum = sum1 + sum2 + sum3 + sum4 + sum5;
if (sum<25)
{
Console.WriteLine("VERY_WEAK");
}
else if(sum>=25&&sum<50)
{
Console.WriteLine("WEAK");
}
else if (sum >= 50 && sum < 60)
{
Console.WriteLine("AVERAGE");
}
else if (sum >= 60 && sum < 70)
{
Console.WriteLine("STRONG");
}
else if (sum >= 70 && sum < 80)
{
Console.WriteLine("VERY_STRONG");
}
else if (sum >= 80 && sum < 90)
{
Console.WriteLine("SECURE");
}
else if (sum >= 90)
{
Console.WriteLine("VERY_SECURE");
}
}
}
}