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

密码验证合格程序

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

#include <iostream>
#include <string>
#include <cctype>
#include <unordered_map>
using namespace std;

bool check_fun1(const string input_str) {
    bool uppercase = false;
    bool lowercase = false;
    bool digit = false;
    bool other = false;
        for (auto c : input_str) {
            if (isupper(c)) {
                uppercase = true;
            } else if (islower(c)) {
                lowercase = true;
            } else if (isdigit(c)) {
                digit = true;
            } else {
                other = true;
            }
        }
        return ((uppercase && lowercase && digit)|| 
                (uppercase && lowercase && other) ||
                (uppercase && digit && other) ||
                (lowercase && digit && other));
} 

bool check_substr(const string& input_str) {
    int n = input_str.size();
    unordered_map<string, int> substr_count;
    for (int len = 3;len < n; len++) {
        for (int i = 0; i <= n - len; i++) {
            string sub = input_str.substr(i, len);
            substr_count[sub]++;
            if (substr_count[sub] > 1) {
                return true;
            }
        }
    }
    return false;
}


int main() {
    string input;
    while (getline(cin, input)) {
        if(input.size() < 8) {
            cout << "NG" << endl;
        } else if (check_fun1(input) == false) {
            cout << "NG" << endl;
        } else if (check_substr(input)) {
            cout << "NG" << endl;
        } else {
            cout << "OK" << endl;
        }
    }
    
    return 0;
}

全部评论

相关推荐

10-13 13:49
南京大学 财务
饿魔:笑死我了,你简直是个天才
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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