题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const splitLength = 8; const getStr = (str: string) => { const targetIndex = str.length % splitLength === 0 ? str.length / splitLength - 1 : Math.floor(str.length / splitLength); for (let i = 0; i <= targetIndex; i++) { const subStr = str.substring(i * splitLength, (i + 1) * splitLength); const targetStr = subStr?.length ? subStr.padEnd(splitLength, "0") : ""; console.log(targetStr); } }; rl.on("line", function (line) { getStr(line); });