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

密码验证合格程序

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

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    while ((line = await readline())) {
        // line = '%Z7';
        // 长度要超过 8 位
        if (line.length <= 8) {
            console.log("NG");
            continue;
        }

        // 查找至少三种符号
        let count = 0;
        if (/[A-Z]/.test(line)) {
            count++;
        }
        if (/[a-z]/.test(line)) {
            count++;
        }
        if (/[0-9]/.test(line)) {
            count++;
        }
        if (/[^A-Za-z0-9]/.test(line)) {
            count++;
        }
        if (count < 3) {
            console.log("NG");
            continue;
        }
        let str1, str2;
        let arr = line.split("");
        let isNG = false;
        if (arr.length >= 6) {
            for (let i = 0; i < arr.length - 6; i++) {
                str1 = arr.slice(i, i + 3).join("");
                for (let j = i + 3; j < arr.length - 2; j++) {
                    str2 = arr.slice(j, j + 3).join("");
                    if (str1 == str2) {
                        isNG = true;
                        break;
                    }
                }
                if (isNG) {
                    console.log("NG");
                    break;
                }
            }
        }
        if (!isNG) {
            console.log("OK");
        }
    }
})();

全部评论

相关推荐

有担当的灰太狼又在摸鱼:零帧起手查看图片
点赞 评论 收藏
分享
每晚夜里独自颤抖:1600一个月?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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