Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
111095 汤奕硕 数组中元素交换 C++ Accepted 2 MS 280 KB 566 2025-02-26 19:10:40

Tests(10/10):


Code:

#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; }