题解 | #参数解析#

参数解析

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]);
        }
    }
})();

全部评论

相关推荐

无情咸鱼王的秋招日记之薛定谔的Offer:好拒信,偷了,希望有机会用到
点赞 评论 收藏
分享
喜欢走神的孤勇者练习时长两年半:池是池,发是发,我曾池,我现黑
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务