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

密码验证合格程序

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

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

bool checkString(const string& a) {
    int isnum = 0;
    int isupper = 0;
    int islower = 0;
    int isother = 0;
    int finder = 0;

    if (a.length() <= 8) {
        return false;
    }

    for (string::const_iterator it = a.begin(); it != a.end(); it++) {
        if (isalpha(*it)) {
            if (abs(*it) >= 97 && abs(*it) <= 123) {
                islower = 1;
            } else if (abs(*it) >= 65 && abs(*it) <= 91) {
                isupper = 1;
            }
        } else if (isdigit(*it)) {
            isnum = 1;
        } else if (*it != ' ' && *it != '\n') {
            isother = 1;
        }
    }

    if (isnum + islower + isupper + isother < 3) {
        return false;
    }

    for (int i = 0; i <= a.size() - 3; i++) {
        string temp = a.substr(i, 3);
        string temp1 = a.substr(0, i);
        string temp2 = a.substr(i + 3);
        string temp3 = temp1 + temp2;
        finder = temp3.find(temp);
        if (finder != string::npos) {
            return false;
        }
    }

    return true;
}

int main() {
    string a;
    while (getline(cin, a)) {
        if (checkString(a)) {
            cout << "OK" << endl;
        } else {
            cout << "NG" << endl;
        }
    }
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 17:10
点赞 评论 收藏
分享
05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 11:27
明天又是董事长面,啥时候是个头啊
积极向上的林同学:董事长亲自面试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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