题解 | 密码验证合格程序

密码验证合格程序

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

#include <cctype>
#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
using namespace std;

bool consist_str(string& str) {
    int n = str.size();
    for (int len = 3; len <= n / 2; len++) {
        for (int i = 0; i <= n - 2 * len; i++) {
            string sub1 = str.substr(i, len);
            for (int j = i + len; j <= n - len; j++) {
                if (str.substr(j, len) == sub1) {
                    return false;
                }
            }
        }
    }
    return true;
}

bool include_all(string& str) {
    vector<int> mark(4);
    for (char& c : str) {
        if (islower(c)) mark[0] = 1;
        else if (isupper(c)) mark[1] = 1;
        else if (isdigit(c)) mark[2] = 1;
        else
            mark[3] = 1;
    }
    int num = 0;
    for (int& m : mark) {
        num += m;
    }
    return num > 2;
}

int main() {
    string str;
    while (getline(cin, str)) {
        if (str.size() > 8 && include_all(str) && consist_str(str)) {
            cout << "OK" << endl;
        } else {
            cout << "NG" << endl;
        }
    }

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

全部评论

相关推荐

面试官问:为什么不考研?该怎么回答啊😭我说现在的就业环境差到底了,还有就是我不想学数学,感觉面试官笑容都凝固了😢
DayDayNoBug的鲜芋球:我说的是“上学期其实尝试过去探索一些研究的方向,但感觉那些对我来说都没有很大的吸引力,相比起研究我可能更喜欢开发这种实践性的东西,它会让我觉得很有意思并且会为之深入进去”(虽然也不知这个回答怎么样哈哈哈哈哈哈)
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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