参数解析(HJ74)

一:解题思路

这道题目的关键在于,当输入字符串有引号包含起来的时候,并且有空格的时候,这个时候应该不要将引号作为输出。

二:完整代码示例 (C++版和Java版)

C++代码:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    vector<string> vec = {};
    string temp = "";

    while (cin >> temp)
    {
        vec.push_back(temp);
    }
    cout << vec.size() << endl;

    string each = "";

    for (int i = 0; i < vec.size(); i++)
    {
        each = vec[i];
        if (each[0] == '\"')
        {
            int len = each.size();
            cout << each.substr(1,len-2) << endl;
        }
        else
            cout << each << endl;
    }

    return 0;
}

 

posted @ 2020-07-31 21:32  repinkply  阅读(720)  评论(0)    收藏  举报