酷代码 AI
菜单
服务商

使用algorithm库简化奇偶分离程序

```cpp #include <iostream> #include <algorithm> #include <vector> int main() { int n; std::cin >> n; std::vector<int> nums(n); for (int i = 0; i < n; ++i) { std::cin >> nums[i]; } std::vector<int> odd, even; std::partition_copy(nums.begin(), nums.end(), std::back_inserter(odd), std::back_inserter(even), [](int x) { return x % 2 != 0; }); for (int num : odd) std::cout << num << " "; std::cout << std::endl; for (int num : even) std::cout << num << " "; return 0; } ``` ######[AI问答 | 201点数解答 | 2026-05-16 19:27:54]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]