题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677?tpId=37&tags=&title=&difficulty=0&judgeStatus=0&rp=1&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D37%26type%3D37
/* 总体思路:解析出参数存放在vector数组中,之后遍历数组打印 需要注意双引号里面的字符串的解析 */ #include<bits/stdc++.h> using namespace std; // 总体思路:解析出参数存放在vector数组中,之后遍历数组打印 int main(){ // 获取输入字符串 string s; getline(cin,s); int len = s.length(); int count=0; vector<string> v; string temp=""; for(int i = 0; i < len; i++){ if(s[i] == '"' && (i != len-1) ){ int j=i+1; while( (j < len) && s[j] != '"'){ j++; } count++; v.push_back(s.substr(i+1, j-i-1)); i=j; }else if(s[i] == ' ' || (i == len - 1) ){ if(i == len - 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; }