HJ87 密码强度等级

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
using namespace std;
int main()
{
	string str;
	cin >> str;
	int lowerletter=0, upperletter=0, digit=0, punct=0;
	for (int i = 0; i < str.size(); i++)
	{
		if (islower(str[i]))
			lowerletter++;
		else if (isupper(str[i]))
			upperletter++;
		else if (isdigit(str[i]))
			digit++;
		else
			punct++;
	}
//	cout<< lowerletter << upperletter << digit << punct << endl;
	int scorelen = 0;
	if (str.size() <= 4)
		scorelen = 5;
	else if (str.size() >= 8)
		scorelen = 25;
	else
		scorelen = 10;
//	cout << "scorelen = " << scorelen << endl;

	int scorealpha = 0;
	if(lowerletter == 0 && upperletter == 0)
		scorealpha = 0;
	else if (lowerletter == 0 || upperletter == 0)
		scorealpha = 10;
	else
		scorealpha = 20;

//	cout << "scorealpha = " << scorealpha << endl;

	int scoredigit = 0;
	if (digit == 0)
		scoredigit = 0;
	else if (digit == 1)
		scoredigit = 10;
	else if(digit > 1)
		scoredigit = 20;

//	cout << "scoredigit = " << scoredigit << endl;

	int scorepunct = 0;
	if (punct == 0)
		scorepunct = 0;
	else if (punct == 1)
		scorepunct = 10;
	else if (punct > 1)
		scorepunct = 25;

//	cout << "scorepunct = " << scorepunct << endl;

	int other = 0;
	if (lowerletter&& upperletter&& scoredigit&& scorepunct)
		other = 5;
	else if ((lowerletter || upperletter) && scoredigit && scorepunct)
		other = 3;
	else if ((lowerletter || upperletter) && scoredigit)
		other = 2;

//	cout << "other = " << other << endl;

	int sum = other + scorepunct + scoredigit + scorealpha + scorelen;

	if (sum >= 90)cout << "VERY_SECURE";
	else if (sum >= 80)cout << "SECURE";
	else if (sum >= 70)cout << "VERY_STRONG";
	else if (sum >= 60)cout << "STRONG";
	else if (sum >= 50)cout << "AVERAGE";
	else if (sum >= 25)cout << "WEAK";
	else if (sum >= 0)cout << "VERY_WEAK";

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值