Official
A - Swap Odd and Even Editorial by en_translator
Swap \(S_{2i-1}\) and \(S_{2i}\) actually for each \(i = 1,2, \ldots, \frac{|S|}{2}\) and print the resulting \(S\). Depending on the language you use, the index may differ by one from the problem statement, because many languages adopt \(0\)-based indexing.
Sample code
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size(); // s の長さを取得
for (int i = 0; i < n / 2; i++) swap(s[2 * i], s[2 * i + 1]);
cout << s << '\n';
}
posted:
last update: