Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
105530 殷佳雨萱 数组中元素交换 C++ Accepted 1 MS 276 KB 542 2025-01-13 20:31:24

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 + 1 < n; i += 2){ swap(a[i], a[i+1]); } // 输出交换后的数组 for(int i = 0; i < n; ++i){ if(i > 0){ cout << " "; } cout << a[i]; } return 0; }