Run ID:111095

提交时间:2025-02-26 19:10:40

#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; // 读取数组长度 vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; // 读取数组元素 } // 交换相邻元素 for (int i = 0; i < n - 1; i += 2) { swap(a[i], a[i + 1]); // 交换第i个和第i+1个元素 } // 输出结果 for (int i = 0; i < n; ++i) { if (i > 0) { cout << " "; } cout << a[i]; } cout << endl; return 0; }