题解 | #字符串分隔#

字符串分隔

https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7

// JavaScript Node
const readline = require('readline')
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
function subChar(args){
    const arr = []
    args.forEach((item,index)=>{
        if(item.length % 8 === 0 && item !== ''){
            for(let i=0;i<item.length;i = i+8){
                const newC = item.substring(i,i+8)
                arr.push(newC)
            }
        }else{
            if(item.length / 8 > 1){
                for(let i=0;i<item.length; i=i+8){
                    if(item.length - i < 8){
                        item = item.substring(i)
                        while(item.length<8){
                            item = item + 0
                        }
                        arr.push(item)
                    }else{
                        const newC = item.substring(i,i+8)
                        arr.push(newC)
                    }
                }
            }else{
                while(item.length<8){
                    item = item + 0
                }
                arr.push(item)
            }
        }
    })
    for(const item of arr){
        console.log(item)
    }
}

rl.on('line', function(line){
    const tokens = line.split(' ')
    subChar(tokens)
})

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-29 17:30
找实习找着找着就要进入7月了,马上秋招也要开始了,找实习还有意义吗?
绝迹的星:有面就面, 没面上就当日薪4位数大佬免费培训, 面上了再考虑要不要实习
点赞 评论 收藏
分享
门口唉提是地铁杀:之前b站被一个游戏demo深深的吸引了。看up主页发现是个初创公司,而且还在招人,也是一天60。二面的时候要我做一个登录验证和传输文件两个微服务,做完要我推到github仓库,还要我加上jaeger和一堆运维工具做性能测试并且面试的时候投屏演示。我傻乎乎的做完以后人家跟我说一句现在暂时不招人,1分钱没拿到全是白干
你的秋招第一场笔试是哪家
点赞 评论 收藏
分享
认真搞学习:这么良心的老板真少见
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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