题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <sstream>
int main() {
string in;
getline(cin, in);
istringstream is(in);
string word;
vector<string> ws;
while (is >> word) {
if (word[0] == '"') {
if (word[word.size() - 1] == '"') {
word.erase(word.begin());
word.erase(word.end()-1);
ws.push_back(word);
} else {
string str;
word.erase(word.begin());
str += word;
do {
is >> word;
str = str + " " + word;
} while (word[word.size() - 1] != '"');
str.erase(str.end()-1);
ws.push_back(str);
}
} else {
ws.push_back(word);
}
}
cout << ws.size() << endl;
for(auto & w : ws){
cout << w << endl;
}
}
比较标准的输入处理
要记得去除头尾的引号
华为机试刷题记录 文章被收录于专栏
记录一下手打代码的解题思路方便复习

