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

密码验证合格程序

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

const readline = require("readline");

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
const hasNoRepeatSubString = (line: string) => {
    for (let i = 0; i < line.length - 3; i++) {
        const sub = line.slice(i, i + 3);
        if (line.slice(i + 3).includes(sub)) {
            return true;
        }
    }
    return false;
};
const regs = [/[a-z]+/, /[A-Z]+/, /[\d]+/, /[^a-z^A-Z^\d]+/];
rl.on("line", function (line: string) {
    let res: "OK" | "NG" = "OK";
    if (
        line?.length <= 8 ||
        regs.filter((reg) => reg.test(line)).length < 3 ||
        hasNoRepeatSubString(line)
    ) {
        res = "NG";
    }
    console.log(res);
});

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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