奇偶位互换

mac2024-12-22  39

一道水题

R - 奇偶位互换

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

Input

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

Output

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

Sample Input

2 0110 1100

Sample Output

1001 1100

代码实现

#include<iostream> #include<string.h> using namespace std; int main() { int c,i; char a[100],temp; cin>>c; getchar(); while(c--) { gets(a); for(i=1;i<=strlen(a)/2;i++) { temp=a[(i-1)*2]; a[(i-1)*2]=a[(i-1)*2+1]; a[(i-1)*2+1]=temp; } puts(a); } return 0; }
最新回复(0)