题解 | #密码验证合格程序#

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

#include <iostream>
#include <string>
#include <vector>
using namespace std;

bool has_sub(string str)
{
	string sub;
	for (int i = 0; i < str.length(); i++)
	{
		sub = str.substr(i, 3);
		for (int j = i + 3; j < str.length(); j++)
		{
			if (str.find(sub, j)!= string::npos) {
				 return true;
			}
		}
	}
	return false;
}

bool has_othersign(string str)
{
	for (int i = 0; i < str.size(); i++)
	{
		if (!isalnum(str[i]) && str[i] != ' ' && str[i] != '\n')
		{
            return true;
		}
	}
	return false;
}

bool has_digit(string str)
{
	for (int i = 0; i < str.size(); i++)
	{
		if (isdigit(str[i]))
			return true;
	}
	return false;
}

bool has_lower(string str)
{
	for (int i = 0; i < str.size(); i++)
	{
		if (islower(str[i]))
			return true;
	}
	return false;
}

bool has_upper(string str)
{
	for (int i = 0; i < str.size(); i++)
	{
		if (isupper(str[i]))
			return true;
	}
	return false;
}

bool morethan3(string str)
{
	int n = 0;
	if (has_upper(str)) n++;
	if (has_lower(str)) n++;
	if (has_digit(str)) n++;
	if (has_othersign(str)) n++;

	return n >= 3;
}

bool morethan8(string str)
{
	return str.length() > 8;
}

bool is_mystic(string str)
{
	if (morethan8(str) && morethan3(str) /*&& sub(str)*/ )
		return true;
	return false;
}

int main()
{
	/*numbers.reserve(50);*/
	string str;
	while (cin >> str)
	{
		if (morethan8(str) && morethan3(str) && !has_sub(str))
			cout << "OK" << endl;
		else
			cout << "NG" << endl;
	}

	return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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