hd 2562 奇偶位互換

奇偶位互換

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4531    Accepted Submission(s): 3476


Problem Description
給定一個長度爲偶數位的0,1字符串,請編程實現串的奇偶位互換。
 


 

Input
輸入包含多組測試數據;
輸入的第一行是一個整數C,表示有C測試數據;
接下來是C組測試數據,每組數據輸入均爲0,1字符串,保證串長爲偶數位(串長<=50)。
 


 

Output
請爲每組測試數據輸出奇偶位互換後的結果;
每組輸出佔一行。
 


 

Sample Input
2 0110 1100
 


 

Sample Output
1001 1100
 


 

Author
yifenfei
 


 

Source
 


 

Recommend

 

 

#include<stdio.h>
#include<string.h>
int main()
{
    int n,t,i;
    char a[60];
    while(scanf("%d",&n)!=EOF)
    {
    getchar();
    while(n--)
    {
    gets(a);
    for(i=0;i<strlen(a);i+=2)
    {
      t=a[i];
      a[i]=a[i+1];
      a[i+1]=t;
                             }
    for(i=0;i<strlen(a);i++)
    {
    printf("%c",a[i]);
}
    printf("\n");

}
}
return 0;    
}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章