题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
#include <iostream>
#include <string>
using namespace std;
#include<vector>
int main() {
vector<string>results;
int i =0,j=0;
bool inQuotes = false;
string str;
getline(cin, str);
while(j<str.size()){
if(str[j]=='"'){
inQuotes = !inQuotes;
if(!inQuotes){
results.push_back(str.substr(i+1,j-i-1));
i=j+1;
}
}
else if (str[j]==' '&&!inQuotes) {
if(i<j){
results.push_back(str.substr(i,j-i));
}
i = j+1;
}
j++;
}
if(i<j){
results.push_back(str.substr(i,j-i));
}
cout<<results.size()<<endl;
for(string result:results){
cout<<result<<endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")
传音控股公司福利 337人发布
