```cpp #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> nums(n); for (int i = 0; i < n; ++i) { cin >> nums[i]; } // 输出奇数 bool first = true; for (int num : nums) { if (num % 2 != 0) { if (!first) { cout << " "; } cout << num; first = false; } } cout << endl; // 输出偶数 first = true; for (int num : nums) { if (num % 2 == 0) { if (!first) { cout << " "; } cout << num; first = false; } } cout << endl; return 0; } ``` 注意事项: 1. 使用vector存储输入数据,避免数组越界问题 2. 使用first标志处理空格输出,确保格式正确 3. 遍历两次数组分别处理奇数和偶数,保持原始顺序 [2025-08-03 07:48:54 | AI写代码神器 | 246点数解答]