题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
第一个想到的思路是条件判断+递归 while(num = readline()){ strSplice(num) } function strSplice(num){ if(num.length<=8){ while(num.length<8){ num+='0' } console.log(num) return } else{ temp = num.slice(0,8) num = num.slice(8) console.log(temp) return strSplice(num) } } 楼里大神的思路 while(str=readline()){ str +='0000000' const length = Math.floor(str.length/8) for(i=0;i<length;i++){ console.log(str.substr(i*8,8)) } }