题解 | #参数解析#

参数解析

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 () {
    const line = await readline();
    let quot = false,list = [],str = "";
    for(const c of line){
        if(c ==="\""){
            if(quot){
                list.push(str);
                str = "";
            }
            quot = !quot;
        }else if(c ===" "){
            if(quot) {
                str+=c;
            }else if(str){
                list.push(str);
                str = "";
            }
        }else {
            str += c;
        }
    }
    if(str) list.push(str);
    console.log(list.length);
    console.log(list.join("\n"));
}()

全部评论

相关推荐

评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务