题解 | #字符串分隔#
字符串分隔
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)
}
}