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

密码验证合格程序

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);
});

全部评论

相关推荐

码农索隆:竞争压力小,就你一个不用卷
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-18 12:01
点赞 评论 收藏
分享
下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
程序员小白条:主要没亮点,项目也是网上的,平平无奇,那只能海投了,奖项总得有一些,然后就是现在最好是前后端都会,自己能做项目并且运维的,要么找星球项目改改,要么找个开源项目改改,自己能拓展功能才是主要的,跟做效率很低很低
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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