题目
描述
•输入一个字符串,请按长度为8拆分每个输入字符串并进行输出;
•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
输入描述:
连续输入字符串(每个字符串长度小于等于100)
输出描述:
依次输出所有分割后的长度为8的新字符串
示例1
输入: abc
输出: abc000000
代码
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())) {
if (line === null || line === "") {
return line;
}
let count = 0;
let strLength = line.length;
const record = [];
while (strLength - count >= 8) {
let result = line.slice(count, count + 8);
record.push(result);
count += 8;
}
if (strLength - count > 0) {
let result = line.slice(count);
let len = 8 - (strLength - count);
for (let index = 0; index < len; index++) {
result += '0'
}
record.push(result)
}
record.forEach(element => {
console.log(element);
});
}
})();