C++ 实现 01 字符串奇偶位互换
#include <iostream>
#include <string>
using namespace std;
string swapBits(string s) {
int n = s.length();
for (int i = 0; i < n; i += 2) {
swap(s[i], s[i+1]);
}
return s;
}
int main() {
int C;
cin >> C;
while (C--) {
string s;
cin >> s;
cout << swapBits(s) << endl;
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/i7II 著作权归作者所有。请勿转载和采集!