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

密码验证合格程序

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

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', function (line) {
    console.log(judge(line) ? 'OK' : "NG")
});


const judge = (input) => {
    if (input.length < 8) return false
    if (!checkTextType(input)) return false
    if (findReduntSubstring(input)) return false
    return true
}

const checkTextType = (input) => {
    const tmp = {
        upperChar: null,
        lowerChar: null,
        num: null,
        symbol: null
    }

    input.split('').forEach((c) => {
        if (c >= 'a' && c <= 'z') tmp['lowerChar'] = true
        else if (c >= 'A' && c <= 'Z') tmp['upperChar'] = true
        else if (c >= '0' && c <= '9') tmp['num'] = true
        else tmp['symbol'] = true
    })

    return Object.values(tmp).filter(Boolean).length >= 3
}

const findReduntSubstring = (input) => {
    for(let i = 0; i <= input.length - 3; i++) {
        const text = input.substring(i, i+3)
        if (input.indexOf(text) !== input.lastIndexOf(text)) return true
    }
    return false
}

全部评论

相关推荐

01-04 14:19
已编辑
重庆科技大学 Java
想和你交朋友的秋田犬...:唉 现在acm已经没那么吃香了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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