题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
#include <bits/stdc++.h> using namespace std; int main(){ string str = ""; while(getline(cin, str)){ int num = 0; //参数个数统计 for(int i = 0; i < str.size(); i++){ if(str[i] == '"'){ i++; // while(str[i] != '"'){ i++; // } } else if(str[i] == ' '){ num++; } } //输出 cout << num + 1 << endl; // num + 1 for(int i = 0; i < str.size(); i++){ if(str[i] == '"'){ i++; while(str[i] != '"'){ cout << str[i]; // i++; } } else if(str[i] == ' '){ cout << endl; // } else{ //为字母 直接输出 cout << str[i]; } } } return 0; }
华为题库题解 文章被收录于专栏
牛客华为题库的题解