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