奇偶位互换

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

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

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

Sample Input
2
0110
1100

Sample Output
1001
1100

 #include "iostream"
using namespace std;
int main()
{
    int n;
    string s;
    char tmp;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        for(int j=0;j<s.length()-1;j+=2)
        {
            tmp = s[j];
            s[j] = s[j+1];
            s[j+1] = tmp;
        }
        cout<<s<<endl;
    }
}