题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
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 isQuote = false;
let str = "";
let arr = [];
let i = 0;
while (i < line.length) {
if (isQuote === false) {
if (/"/.test(line[i])) isQuote = true;
else {
if (/ /.test(line[i])) {
if (str !== "") arr.push(str);
str = "";
} else str = str.concat(line[i]);
if (i === line.length - 1) arr.push(str);
}
} else {
if (/"/.test(line[i])) {
arr.push(str);
str = "";
isQuote = false;
} else {
str = str.concat(line[i]);
}
}
i++;
}
console.log(arr.length);
for (let j = 0; j < arr.length; j++) {
console.log(arr[j]);
}
}
})();
查看4道真题和解析

