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

密码验证合格程序

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()) {
        let r = isPs(line);
        console.log(r)
    }



}()


function isPs(password) {
    //48 - 57 数字
    //97 - 122 小写字母
    //65 - 90 大写字母
    // 32 空格 10 换行    
    if (password.length < 9) {
        return 'NG'
    }
    let hasNumber, hasLowerChar, hasUpperChar, hasOther;
    for (let i = 0; i < password.length; i++) {
        const code = password.charCodeAt(i);
        if (48 <= code && code <= 57) {
            hasNumber = true
            continue;
        }
        if (97 <= code && code <= 122) {
            hasLowerChar = true
            continue;
        }
        if (65 <= code && code <= 90) {
            hasUpperChar = true
            continue;
        }
        if (code != 32 && code != 10) {
            hasOther = true
        }
    }
    const num = [hasNumber, hasLowerChar, hasUpperChar, hasOther].reduce((count, i) => {
        count += (i ? 1 : 0);
        return count
    }, 0)
    if (num < 3) {
        return 'NG'
    }
    for (let i = 0; i < password.length - 6; i++) {
        for (let j = i + 3; j < password.length - 3; j++) {
            if (password.substring(i, i + 3) === password.substring(j, j + 3)) {
                return 'NG'
            }
        }
    }
    return 'OK'
}

全部评论

相关推荐

牛客583549203号:腾讯还好,况且实习而已,实习生流动性很大,属于正常现象,记得和HR委婉解释
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务