题解 | #字符串分隔#

字符串分隔

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

获取输入,调用递归处理字符串

const readline = require('readline')

var rl = readline.createInterface({
    input:process.stdin,
    output:process.stdout
})
var arr = []
rl.on('line',(line)=>{
    arr.push(line)
})
rl.on('close',()=>{
    arr.forEach(val=>{
        if(val.length<8){
            if(val.length > 0){
                add(val)
            }
        }else{
            sliceStr(val)
        }
    })
})

function add(str){
    str = str + 0
    if(str.length < 8){
        add(str)
    }else{
        console.log(str)
        return str
    }
}

function sliceStr(str){
    console.log(str.slice(0,8))
    str = str.slice(8)
    if(str.length <8){
        if(str.length >0){
            add(str)
        }
    }else{
        sliceStr(str)
    }
}
全部评论

相关推荐

投递腾讯云智研发等公司6个岗位
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务