题解 | #字符串分隔#

字符串分隔

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())) {
        let str = line;
        let strArr = [];
        let count = 0;
        let eightStr = "";
        let strarrs = str.split("");
        for (let i = 0; i < strarrs.length; i++) {
            eightStr += strarrs[i];
            if (eightStr.length == 8){
                // 如果eightStr的length到8了,加入到strArr去
                strArr.push(eightStr);
                eightStr = '';
            } else if( i == strarrs.length-1) {
                let left0Count = 8 - eightStr.length;
                for (let j = 0; j < left0Count; j++) {
                    eightStr += "0";
                }
                strArr.push(eightStr);
                eightStr = '';
            }
        }
        strArr.forEach((item) => {
            console.log(item);
        });
    }
})();

全部评论

相关推荐

2024-12-11 14:09
已编辑
中国海洋大学 数值策划
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务