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

密码验证合格程序

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

注意代码规范,自己写的(仅供参考)

#include <bits/stdc++.h>
using namespace std;
bool chongFu (string str) {
	int n = str.size();
	set<string> rec;
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 2; j < n; j++) {
			string s = str.substr(i, j - i + 1);
			auto it = rec.find(s);
			if (it == rec.end()) {
				rec.insert(s);
			} else {
				if (str[i - 1] == str[i + 1])
					continue;
				else
					return false;
			}
		}
	}
	return true;
}
int main () {
	vector<string> str;
	string s;
	while (cin >> s) {
		str.push_back(s);
	}
	for (string it : str) {
		int n = it.size();
		vector<int> num(4, 0);

		if (n > 8) {
			if (!chongFu(it)) {
				cout << "NG" << endl;
				continue;
			}
			for (int i = 0; i < n; i++) {
				if (it[i] == ' ') {
					cout << "NG" << endl;
				} else if (it[i] >= '0' && it[i] <= '9') {
					num[0] = 1;
				} else if (it[i] >= 'a' && it[i] <= 'z') {
					num[1] = 1;
				} else if (it[i] >= 'A' && it[i] <= 'Z') {
					num[2] = 1;
				} else {
					//cout << it[i] << endl;
					num[3] = 1;
				}
			}
			if (num[0] + num[1] + num[2] + num[3] >= 3) {
				cout << "OK" <<endl;
			} else
				cout << "NG" << endl;
		} 
		else {
			cout << "NG" << endl;
		}
		//cout << it <<endl;
	}
	return 0;
}
全部评论

相关推荐

05-07 17:58
门头沟学院 Java
wuwuwuoow:1.简历字体有些怪怪的,用啥写的? 2.Redis 一主二从为什么能解决双写一致性? 3.乐观锁指的是 SQL 层面的库存判断?比如 stock > 0。个人认为这种不算乐观锁,更像是乐观锁的思想,写 SQL 避免不了悲观锁的 4.奖项证书如果不是 ACM,说实话没什么必要写 5.逻辑过期时间为什么能解决缓存击穿问题?逻辑过期指的是什么 其实也没什么多大要改的。海投吧
点赞 评论 收藏
分享
05-25 10:45
西华大学 Java
Frank_zhang:没实习一个项目肯定不够,可以再做一个轮子,技术栈再补一个mq,微服务,整体再换个简历模板,暑期尽量再找一个日常实习
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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