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

密码验证合格程序

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

#include<iostream>
using namespace std;
string isValid(string password);
string condition_2(string password);
string isSubRepeat(string password);

int main() {
    string password;
    while (cin >> password) {
        cout << isValid(password) << endl;
    }
}

string isValid(string password) {
    if (password.length() <= 8)
        return "NG";
    else
        return condition_2(password);
}

string condition_2(string password) {
    int condition[4] = { 0 };//condition[0]表示是否有数字,1大写字母,2小写字母,3其它字符
    for (int i = 0; i < password.length(); i++) {
        char ch = password[i];
        if (isdigit(ch))
            condition[0] = 1;
        else if (ch >= 'A' && ch <= 'Z')
            condition[1] = 1;
        else if (ch >= 'a' && ch <= 'z')
            condition[2] = 1;
        else {
            if (ch != ' ')
                condition[3] = 1;
        }
    }
    int sum = 0;
    for (int i = 0; i < 4; i++)
        sum += condition[i];
    if (sum >= 3)
        return isSubRepeat(password);
    else
        return "NG";

}

string isSubRepeat(string password) {
    string sub1, sub2;
    for (int i = 0; i < password.length() - 3; i++) {
        sub1 = password.substr(i, 3);
        for (int j = 0; j < password.length() - 3; j++) {
            if (i != j) {
                sub2 = password.substr(j, 3);
                if (sub1 == sub2)
                    return "NG";
            }
        }

    }
    return "OK";
}

全部评论

相关推荐

喵喵喵6_6:包大的,也看部门,产品线赶着交付时疯狂加班,预研部门轻松点,124九点,35七点,周六有活就报加班。 氛围得看领导咋样。 但是最烦人的是内部的拉通对齐会随时打断你手上的活,代码写不了一点
点赞 评论 收藏
分享
牛客98820962...:个人意见,我觉得实习和项目经历要一致,达美乐感觉没必要写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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