#include <iostream> #include <string> #include <vector> #include <algorithm> #include <map> using namespace std; bool verifyStrType(string& str); bool verify(string& str); int main() { vector<string> inputs; string line; while (getline(cin, line)) { if (line.empty()) { break; } inputs.push_back(line); } for (string s : inputs) if (verify(s)) { cout << "OK" << endl; } else { cout << "NG" << endl; } return 0; } // 校验 字符串 bool verify(string& str) { // 长度不少于 8 位 if (str.size() < 8) return false; // 校验是否至少有3中类型; if (!verifyStrType(str)) return false; map<string, int> dict; for (int i = 0; i < str.size() - 2; i++) { // substr 第二个参数是 长度; string sub = str.substr(i, 3); // 只需要判断 为3的存不存在就可以了,如果为3的都不存在,其他的长度更不存在; if (dict.find(sub) != dict.end()) { // 若字典中找到了 说明重复; return false; } else { // 不重复就记录到字典中; dict[sub] = i; } } return true; } // 校验 必须包含大写字母、小写字母、数字、特殊字符中的至少三种 bool verifyStrType(string& str) { vector<bool> type = vector<bool>(4, 0); for (char c : str) { // 数字 if (isdigit(c)) { type[0] = 1; } // 大写字母 else if (isupper(c) ) { type[1] = 1; } // 小写字母 else if (islower(c) ) { type[2] = 1; } else { type[3] = 1; } } int sum = 0; for (int i : type) { sum += i; } return sum >= 3; }