题解 | #字符串分隔#

字符串分隔

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))
    }
}

全部评论

相关推荐

星辰再现:裁员给校招生腾地方
点赞 评论 收藏
分享
07-01 23:23
郑州大学 Java
否极泰来来来来:牛客迟早有高三的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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