JS node 题解 | #字符串分隔#

字符串分隔

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

const rl = require("readline").createInterface({ 
    input: process.stdin,
    output: process.stfout
});
// 输入单行
rl.on('line', function(line) {
    if (line.length === 0) {
        console.log(line)
        return
    }
    if (line.length % 8 !== 0) {
        const tmp = []
        for (let i=0;i<(8-(line.length % 8));i++) {
            tmp.push('0')
        }
        let newlist = tmp.join().replace(/,/g, '')
        const formatList = line.concat(newlist)
        for (let i=0; i<(formatList.length/8);i++) {
            console.log(formatList.substr(i*8, 8))
        }
    } else {
        for (let i=0; i<(line.length/8);i++) {
            console.log(line.substr(i*8, 8))
        }
    }
})

全部评论

相关推荐

Sigma429:极兔啊,薪资开的巨低,还在上海,索性不做笔试了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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