c++的几个内置函数

islower(char c) 是否为小写字母
isuppper(char c) 是否为大写字母
isdigit(char c) 是否为数字
isalpha(char c) 是否为字母
isalnum(char c) 是否为字母或者数字
toupper(char c) 字母小转大
tolower(char c) 字母大转小

#include <iostream>
#include <string>

using namespace std;

const string Err = "NG";
const string Ok = "OK";

enum type {
    LOWER,
    UPPER,
    DIGIT,
    OTHER,
    MAX,
};

int main(void)
{
    string s;

    while (cin >> s){
        //cout << "s : " << s << endl;

        if (s.size() <= 8){
            cout << Err << endl;
            continue;
        }

        int State[type::MAX] = {0};
        for (char c : s){
            if (islower(c)){
                State[type::LOWER] += 1;
            }else if (isupper(c)){
                State[type::UPPER] += 1;
            }else if (isdigit(c)){
                State[type::DIGIT] += 1;
            }else{
                State[type::OTHER] += 1;
            }
        }
        int typenum = 0;
        for (int i = 0; i < type::MAX; ++i){
            if (State[i] > 0) typenum += 1;
        }

        if (typenum < 3){
            cout << Err << endl;
            continue;
        }

        // 判断有没有长度超过 2 的子串
        int max_substr_len = 3;
        string target;
        bool isFound = false;
        for (int i = 0; i < s.size()-max_substr_len; i ++){
            for (int j = i + max_substr_len; j < s.size()-max_substr_len; j ++){
                // 如果字符串相同
                if (0 == s.compare(i, max_substr_len, s, j, max_substr_len)){
                    isFound = true;
                    break;
                }
            }
            if (isFound) break;
        }
        if (isFound)
            cout << Err << endl;
        else
            cout << Ok << endl;

    }

    return 0;
}