题解 | #参数解析#
参数解析
https://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string inp; getline(cin, inp); int N = inp.size(); vector<string> res; string t; int j = 0; for (int i = 0; i <= N; i++) { if (inp[i] == '"') { j = i + 1; i++; while (inp[i] != '"') i++; res.push_back(inp.substr(j, i - j)); i += 1; j = i + 1; } else if (i == N || inp[i] == ' ') { res.push_back(inp.substr(j, i - j)); j = i + 1; } } cout << res.size() << endl; for (auto it : res) cout << it << endl; } // 64 位输出请用 printf("%lld")
模拟
#华为OD机试真题#