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

#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;
}