65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
typedef char STRING[50];
void ExchangeBit(STRING s)
{
while(*s)
{
char temp=*s;
*s=*(s+1);
*(s+1)=temp;
s+=2;
}
}
void main()
{
cout<<"输入测试的组数"<<endl;
int num;
cin>>num;
cout<<"输入测试串"<<endl;
STRING * pSTRING=new STRING[num];
int i=0;
while(i<num)
cin>>pSTRING[i++];
cout<<"output:"<<endl;
for(i=0;i<num;i++)
{
ExchangeBit(pSTRING[i]);
cout<<pSTRING[i]<<endl;
}
}
/*
输入测试的组数
2
输入测试串
0110
1100
output:
1001
1100
请按任意键继续. . .
*/
#include <stdio.h>
#include <string.h>
void change(char *s, int n)
{
int i;
for (i = 0; i < n; i += 2)
{
char tem;
tem = s[i];
s[i] = s[i+1];
s[i+1] = tem;
}
}
int main(int argc, char *argv[])
{
int n;
scanf("%d", &n);
while (n-- > 0)
{
char a[51] = { '\0' }; /*保证串长为偶数位(串长 <=50)*/
scanf("%s", a);
change(a, strlen(a));
printf("%s\n", a);
}
return 0;
}