题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
#include<bits/stdc++.h>
using namespace std;
// 总体思路:解析出参数存放在vector数组中,之后遍历数组打印
int main(){
string s;
getline(cin,s);
int n=s.length();
int count=0;
vector<string> v;
string temp="";
for(int i=0;i<n;i++){
if(s[i]=='"' && (i!=n-1) ){
int j=i+1;
while( (j < n) && s[j] != '"'){
j++;
}
count++;
v.push_back(s.substr(i+1,j-i-1));
i=j;
}else if(s[i]==' '||(i==n-1)){
if(i==n-1){
temp+=s[i]; // 最后一个字符
}
if(temp != ""){
v.push_back(temp);
count++;
}
temp="";
}else{
temp+=s[i];
}
}
cout << count << endl;
for(auto item:v){
cout << item << endl;
}
return 0;
}
小天才公司福利 1282人发布
