华为机试:密码验证合格程序

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

bool number(string str) {
    for (char ch : str) {
        if (ch >= '0' && ch <= '9') {
            return true;
        }
    }
    return false;
}

bool uppchar(string str) {
    for (char ch : str) {
        if (ch >= 'A' && ch <= 'Z') {
            return true;
        }
    }
    return false;
}

bool lowchar(string str) {
    for (char ch : str) {
        if (ch >= 'a' && ch <= 'z') {
            return true;
        }
    }
    return false;
}

bool others(string str) {
    for (char ch : str) {
        if ((ch < '0' || (ch > '9' && ch < 'A') || (ch > 'Z' && ch < 'a') ||
                ch  > 'z') && ch != ' ' && ch != '\n') {
            return true;
        }
    }
    return false;
}

bool sub_string(string str) {
    string A, B;
    int i, j;
    for (i = 0; i < str.size() - 3; i++) {
        for (j = i + 1; j < str.size() - 2; j++) {
            A = str.substr(i, 3);
            B = str.substr(j, 3);
            if (A == B) {
                return false;
            }
            A.clear();
            B.clear();
        }
    }
    return true;
}

int main() {
    // int a, b;
    // while (cin >> a >> b) { // 注意 while 处理多个 case
    //     cout << a + b << endl;
    // }
    string str;
    while (cin >> str) {
        if (str.size() < 8) {
            cout << "NG" << endl;
            continue;
        }
        int count = 0;
        count = number(str) + uppchar(str) + lowchar(str) + others(str);
        if (count < 3) {
            cout << "NG" << endl;
            continue;
        }
        if (!sub_string(str)) {
            cout << "NG" << endl;
            continue;
        }
        cout << "OK" << endl;
    }
}

全部评论
题目见得比较少
点赞 回复 分享
发布于 2023-02-10 18:24 广东
稳的老哥,进了吗?
点赞 回复 分享
发布于 2023-02-10 18:03 辽宁

相关推荐

饿魔:看到在线简历了吧
点赞 评论 收藏
分享
评论
1
8
分享

创作者周榜

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