题解 | #参数解析#

参数解析

https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677

#include <iostream>
#include <string>
using namespace std;
#include<vector>
int main() {
    vector<string>results;
    int i =0,j=0;
    bool inQuotes = false;
    string str;
    getline(cin, str);
    while(j<str.size()){
        if(str[j]=='"'){
            inQuotes = !inQuotes;
            if(!inQuotes){
                results.push_back(str.substr(i+1,j-i-1));
                i=j+1;
            }
        }
        else if (str[j]==' '&&!inQuotes) {
            if(i<j){
                results.push_back(str.substr(i,j-i));
            }
            i = j+1;
        }
        j++;
    }
    if(i<j){
        results.push_back(str.substr(i,j-i));
    }
    cout<<results.size()<<endl;
    for(string result:results){
        cout<<result<<endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

12-02 20:08
已编辑
门头沟学院 后端工程师
notbeentak...:孩子,说实话,选择很重要,可能你换一个方向会好很多,但是现在时间不太够了,除非准备春招
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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