当前位置: 代码迷 >> 综合 >> 奇偶位互换 2562
  详细解决方案

奇偶位互换 2562

热度:81   发布时间:2023-12-18 22:55:49.0

Problem Description

给定一个长度为偶数位的0,1字符串,请编程实现串的奇偶位互换。

Input

输入包含多组测试数据;
输入的第一行是一个整数C,表示有C测试数据;
接下来是C组测试数据,每组数据输入均为0,1字符串,保证串长为偶数位(串长<=50)

Output

请为每组测试数据输出奇偶位互换后的结果;
每组输出占一行。

Sample Input

2

0110

1100

Sample Output

1001

1100

#include <iostream>
#include <string>
int main(int argc, const char *argv[])
{
int c = 0;
std::cin >> c;
while(c --)
{
std::string str;
std::cin >> str;
for(int i = 0;i < str.size();i += 2)
{
char ch = str[i];
str[i] = str[i + 1];
str[i + 1] = ch;
}
std::cout << str << std::endl;
}
//system("pause");
return 0;
}