题解 | #参数解析#
参数解析
http://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
vector<string>vec;
int i=0;
while(i<str.size())
{
string s;
bool f=false;
if(str[i]=='"')
{
i++;
while(str[i]!='\0'&&str[i]!='"')
{
s.push_back(str[i]);
f=true;
i++;
}
}
else
{
while(str[i]!='\0'&&str[i]!=' ')
{
s.push_back(str[i]);
f=true;
i++;
}
}
i++;
if(f){
vec.push_back(s);
}
}
cout<<vec.size()<<endl;
for(int c=0;c<vec.size();c++)
{
string outstr=vec[c];
int i=count(outstr.begin(),outstr.end(),'"');
if(i>0)
{
int j=0;
string ts;
while(outstr[j]!='\0')
{
if(outstr[j]!='"')
{
ts.push_back(outstr[j]);
}
j++;
}
outstr=ts;
}
cout<<outstr<<endl;
}
}
}