题解 | #参数解析#

参数解析

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

#include <cstddef>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
    vector<string> aug;
    string tmp;
    cin >> tmp;
    aug.push_back(tmp);
    while (cin >> tmp)
    {
        if (tmp.find('\"') != string::npos)
        {
            tmp = tmp.substr(1);
            if (tmp.find('\"') != string::npos)
            {
               tmp.resize(tmp.size()-1);
               aug.push_back(tmp);
               continue; 
            }
            string str;
            while (cin >> str)
            {
                if (str.find('\"') == string::npos)
                {
                    tmp = tmp + ' ' + str;
                }
                else  
                {
                    str.resize(str.size()-1);
                    tmp  = tmp + ' ' + str;
                    aug.push_back(tmp);
                    break;
                }
            }
        }
        else  
        {
            aug.push_back(tmp);
        }
    }
    cout << aug.size() << endl;
    for (auto s : aug)
    {
        cout << s << endl;
    }
    return 0;
}

朴素解法,照着题意一步步判断

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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