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

密码验证合格程序

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 res =await ifValidate(line)
        console.log(res)
    }
}()

async function ifValidate(str){
    let count = 0
    if(str.length < 9){
        return 'NG'
    }
    if(/[a-z]/.test(str)){
        count++
    }
    if(/[A-Z]/.test(str)){
        count++
    }
    if(/[0-9]/.test(str)){
        count++
    }
    if(/[^0-9a-zA-Z]/.test(str)){
        count++
    }
    if(count >= 3){
        if(await ifRepeat(str)){
            return 'NG'
        }else{
            return 'OK'
        }
    }else{
        return 'NG'
    }
}

async function ifRepeat(str){
    for(let i=0;i<str.length-2;i++){
        let subStr = str.substring(i,i+3)
        let tmpStr = str.substring(0,i)+str.substring(i+3)
        if(tmpStr.includes(subStr)){
            return true
        }else{
            continue
        }
    }
}

主要修改了判断重复这里,修改了一种自己更好理解的方法

#华为机试,emo了#
全部评论

相关推荐

渐好:软光栅真的写明白了吗,既然是软渲那技术栈不应该使用OpenGL,光追和bvh既不算什么高级渲染技术更不应该属于软渲的内容,git那个项目没啥用,建议把前两个项目重新组织一下语言,比如软渲染那个项目 冯着色和msaa、贴图这几项分开写,写的到位点,如果你还学过光追那就单独写出来,如果没把握考官问你答不上来就别写给自己找麻烦,在技术栈那一栏简单提一下自己学过就行,这样杂的放在一起不太严谨,个人愚见.
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务