Run ID:105530

提交时间:2025-01-13 20:31:24

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