题解 | 密码验证合格程序

密码验证合格程序

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

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

int main() {
    string input;
    while(cin >> input){
        bool is_ng = false;
        if(input.size() < 8){
            cout << "NG" << endl;
            is_ng = true;
            continue;
        }
        uint8_t big = 0;
        uint8_t small = 0;
        uint8_t num = 0;
        uint8_t special = 0;
        uint8_t count = 0;
        for(char& c : input){
            if((c >= 33 && c <= 47) || (c >= 58 && c <= 64) || (c >= 91 && c <= 96) || (c >= 123 && c <= 126)){
                if(special == 0){
                    special = 1;
                    count++;
                }
            }else if((c >= 48 && c <= 57)){
                if(num == 0){
                    num = 1;
                    count++;
                }
            }else if((c >= 65 && c <= 90)){
                if(big == 0){
                    big = 1;
                    count++;
                }
            }else if((c >= 97 && c <= 122)){
                if(small == 0){
                    small = 1;
                    count++;
                }
            }
        }
        if(count < 3){
            is_ng = true;
            cout << "NG" << endl;

            continue;
        }

        string substr1;
        string substr2;
        for(size_t begin = 0; begin < input.size(); begin++){
            for(size_t length = 3; length < input.size(); length++){
                if(input.size() - (begin + length) <= 2){
                    break;
                }
                if(begin + length >= input.size()){
                    break;
                }
                substr1 = input.substr(begin, length);
                size_t substr_begin = begin + length;
                while(substr_begin + length < input.size()){
                    substr2 = input.substr(substr_begin, length);
                    if(substr1 == substr2){
                        is_ng = true;
                        cout << "NG" << endl;
                        break;
                    }
                    substr_begin++;
                }
                //cout << substr1 << endl;
                //cout << substr2 << endl;
            }

        }
        if(!is_ng){
            cout << "OK" << endl;
        }
        //cout << "OK" << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

给我发了笔试链接,想着等晚上回去做,结果还没做流程就终止了
伟大的小黄鸭在学习:我猜就是笔试几乎没用,就是用来给用人部门拖时间复筛简历的,可能用人部门筛到你简历觉得不合适就提前挂了
投递小鹏汽车等公司10个岗位
点赞 评论 收藏
分享
苍蓝星上艾露:这简历。。。可以试试我写的开源简历优化工具https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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