题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
#include <iostream> #include <string> using namespace std; const int analyse(const string s) { //参数个数 int num = 0; //是否在""外 bool flag = true; //统计参数个数 for (char ch : s) { if (ch == '"') flag = !flag; if (ch == ' ') if (flag) num++; } //行末没有空格,应将最后一个单词单独计入 num++; cout << num << endl; //输出参数 for (char ch : s) { if (ch == '"') flag = !flag; else if ((ch == ' ') && (flag)) cout << endl; else cout << ch; } return num; } int main() { string s; while (getline(cin, s)) { // 注意 while 处理多个 case analyse(s); } } // 64 位输出请用 printf("%lld")