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

密码验证合格程序

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()){
        console.log(isQualify(line) ? 'OK' : 'NG')
    }
}()

function isQualify(str) {
    let type = 0
    if (str.length < 9 || str.includes('\n') || str.includes(' ')) return false;
    if (/[a-z]/.test(str)) {
        // 小写字母
        type++;
    }
    if (/[A-Z]/.test(str)) {
        // 大写字母
        type++;
    }
    if (/[0-9]/.test(str)) {
        // 数字
        type++;
    }
    // 其他符号(取反,非汉字非大小写非数字)
    if (/[^a-zA-z0-9]/.test(str)) type++;
    if(type < 3) return false;

    // 判断是否有长度大于 2 的包含公共元素的子串重复
    for (let i = 0; i < str.length - 2; i++) {
        let b = str.split(str.slice(i, i+3));
        if (b.length > 2) return false;
    }

    return true;

}

全部评论

相关推荐

06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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