题解 | #字符串分隔#

字符串分隔

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-26 18:30
门头沟学院 Java
据说名字越长别人越关...:你问问这里面有多少是正经候选人,而不是乱打招呼的
点赞 评论 收藏
分享
鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
ResourceUt...:你是我见过最美的牛客女孩
晒一下我的毕业照
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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