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

密码验证合格程序

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

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

//三个限制 那就设置三个步骤即可
bool fun1(string str)
{
	//长度必须超过八位
	if (str.length() <= 8)
	{
		return false;
	}
	//要有大小写字母,数字,其他字符至少三种
	//可不可以用ascII码来进行区分
	int count = 0; //设置一个数字标志位 用来确定是否已经使用了数字
	int Icount = 0;//大写标志位
	int icount = 0;//小写
	int xcount = 0;//其他标志位
	for (int i = 0; i < str.length(); i++)
	{ 
		//把标志位判断放到外面的if 可能会导致其他字符那里出现问题
		//为数字
		if ((*(str.substr(i,1).data())>='0') 
			&& (*(str.substr(i, 1).data()) <= '9'))
		{
			if (count == 0)
			{
				count=1;
			}
			continue;
		}
		//为大写字母
		else if ((*(str.substr(i, 1).data()) >= 'A')
			&& (*(str.substr(i,  1).data()) <= 'Z'))
		{
			if (Icount == 0)
			{
				Icount=1;
			}
			continue;
		}
		//为小写字母
		else if ((*(str.substr(i,  1).data()) >= 'a')
			&& (*(str.substr(i, 1).data()) <= 'z'))
		{
			if (icount == 0)
			{
				icount = 1;
			}
			continue;
		}
		//为其他字符  
		else if ((*(str.substr(i, 1).data()) != ' ')
			&& (*(str.substr(i, 1).data()) != '\n')
			&& xcount == 0)
		{
			xcount = 1;
			continue;
		}
		//判断是否已经满足条件了 不需要继续往后判断了
		if ((count + icount + Icount + xcount) >= 3)
		{
			break;
		}
	}
	if ((count + icount + Icount + xcount) < 3)
	{
		return false;
	}
	//不能有长度大于2的包含公共元素的子串重复 不能有3以及以上的
	//遍历
	string strdata;
	for (int i = 0; i < str.length()-3; i++)
	{
		strdata = str.substr(i, 3);
		for (int j = i+1; j < str.length()-3; j++)
		{
			if (strdata == str.substr(j,3))
			{
				return false;
			}
		}
	}
	return true;

}
int main()
{
	string str;
	while (cin >> str)
	{
		bool iftrue = fun1(str);
		if (iftrue)
		{
			cout << "OK" << endl;
		}
		else
		{
			cout << "NG" << endl;
		}


	}
	system("pause");
	return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-16 18:05
何尝不是一种学历歧视呢
下午吃泡馍:这种公司不投也罢,不过建议挂出公司名字,1.1w就应激到问是不是清北也是看得出来不是啥好公司了,估计这hr也没见过啥世面
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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