题解 | #密码强度等级#

密码强度等级

https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361

// HJ87-2 密码强度等级.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
	string s;
	while (getline(cin, s))
	{
		int len = s.size(), up = 0, low = 0, num = 0, ch = 0,score=0;
		int ss = 0, sa = 0, sn = 0, sc = 0, so = 0;
		if (len <= 4)
		{
			ss = 5;
		}
		else if (len >= 5 && len <= 7)
		{
			ss = 10;
		}
		else if (len >= 8)
		{
			ss = 25;
		}
		for (int i = 0; i < s.size(); i++)
		{
			if (isupper(s[i]))
			{
				up++;
			}
			else if (islower(s[i]))
			{
				low++;
			}
			else if (isdigit(s[i]))
			{
				num++;
			}
			else
			{
				ch++;
			}
		}
		if (up == 0 && low == 0)
		{
			sa = 0;
		}
		else if (up > 0 && low == 0 || up == 0 && low > 0)
		{
			sa = 10;
		}
		else if (up > 0 && low > 0)
		{
			sa = 20;
		}
		if (num == 0)
		{
			sn = 0;
		}
		else if (num == 1)
		{
			sn = 10;
		}
		else if (num > 1)
		{
			sn = 20;
		}
		if (ch == 0)
		{
			sc = 0;
		}
		else if (ch == 1)
		{
			sc = 10;
		}
		else if (ch > 1)
		{
			sc = 25;
		}
		if (up > 0 && low > 0 && num > 0 && ch > 0)
		{
			so = 5;
		}
		else if ((up > 0 && num > 0 && ch > 0) || (low > 0 && num > 0 && ch > 0))
		{
			so = 3;
		}
		else if ((up > 0 && num > 0) || (low > 0 && num > 0))
		{
			so = 2;
		}
		score = ss + sa + sn + sc + so;
		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 if (score >= 0)
		{
			cout << "VERY_WEAK" << endl;
		}
	}
	return 0;
}

全部评论

相关推荐

兄弟们你们进大厂靠的是什么项目啊
DOTPHTP:课设改。其实项目什么的如果不是实习里面的生产项目的话,建议✍️那种自己想要做的。突出个人自驱力,而不是为了找工作不得不随波逐流这种
点赞 评论 收藏
分享
能干的三文鱼刷了100道题:公司可能有弄嵌入式需要会画pcb的需求,而且pcb能快速直观看出一个人某方面的实力。看看是否有面试资格。问你问题也能ai出来,pcb这东西能作假概率不高
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务