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


查看17道真题和解析