本质好像还是暴力,但用正则能简化两级循环;

思路来源于各位大佬题解

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

bool isOk(string s){
    if(s.length() <= 8) return false;
    
    int sum = 0;
    if(regex_search(s, regex("[a-z]"))) sum ++;
    if(regex_search(s, regex("[A-Z]"))) sum ++;
    if(regex_search(s, regex("\\d"))) sum ++;
    if(regex_search(s, regex("[^\\d a-z A-Z]"))) sum ++;

    if(sum < 3) return false;

    regex pattern(R"((.{3,}).*\1)");
    if(regex_search(s, pattern)) return false;

    return true;
}

void isValue(vector<string> ss){
    for(string s: ss){
        if(isOk(s)) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
}

int main() {
    vector<string> ss;
    string s;
    while(getline(cin, s)) ss.push_back(s);

    isValue(ss);

    return 0;
}
// 64 位输出请用 printf("%lld")