Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
108125 朱彦宇 数组中元素交换 C++ Wrong Answer 1 MS 268 KB 587 2025-01-19 14:37:44

Tests(0/10):


Code:

#include <iostream> #include <vector> using namespace std; vector<int> swapAdjacentElements(vector<int>& a) { vector<int> result; for (size_t i = 0; i < a.size(); i += 2) { if (i + 1 < a.size()) { result.push_back(a[i + 1]); result.push_back(a[i]); } else { result.push_back(a[i]); } } return result; } int main() { vector<int> a = {1, 2, 3, 4, 5}; vector<int> swapped = swapAdjacentElements(a); for (int num : swapped) { cout << num << " "; } return 0; }


Run Info:

------Input------
1 49
------Answer-----
49
------Your output-----
2 1 4 3 5