题解 | #字符串分隔#

字符串分隔

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

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    while(line = await readline()){
        //字符串长度小于8
        if(line.length < 8){
            while(line.length < 8) {
                line = line + '0';
            }
            console.log(line);
        } else{
            //字符串长度大于等于8
            let indexStart = 0;
            while(line.length - indexStart > 8){
                console.log(line.slice(indexStart, indexStart + 8))
                indexStart += 8;
            }
            //剩余长度补齐
            let leftLetters = line.slice(indexStart)
            while(leftLetters.length < 8) {
                leftLetters = leftLetters + '0';
            }
            console.log(leftLetters);
        }
    }
}()

全部评论

相关推荐

哇哇的菜鸡oc:他这不叫校招offer,而是实习offer
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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