题解 | #参数解析#
参数解析
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;
}
朴素解法,照着题意一步步判断
韶音科技公司氛围 647人发布