酷代码 AI
菜单
服务商

使用 C++ 分别输出输入数组中的奇数和偶数

```cpp #include <iostream> #include <algorithm> using namespace std; int n, a[105]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } bool first_odd = true; for (int i = 0; i < n; i++) { if (a[i] % 2 != 0) { if (!first_odd) cout << " "; cout << a[i]; first_odd = false; } } cout << endl; bool first_even = true; for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) { if (!first_even) cout << " "; cout << a[i]; first_even = false; } } cout << endl; return 0; } ``` ######[AI问答 | 255点数解答 | 2026-05-16 19:26:57]

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