65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <cstring>
#define Max 100
using namespace std;
int main()
{
int i;
bool judge(char *,char *);
void exchange(char *,char *);
char a[Max],b[Max],c[Max];
gets(a);
gets(b);
gets(c);
if(judge(a,b)) exchange(a,b);
if(judge(a,c)) exchange(a,c); // 你的参数写错了
if(judge(b,c)) exchange(b,c);
cout <<a <<endl; // 这样输出字符串,即使要输出第一个字符,也必须初始化i
cout <<b <<endl;
cout <<c <<endl;
return 0;
}
bool judge(char *q1,char *q2) // 这个函数这样写
{
int i;
for (i = 0; i < Max; ++i) {
if (*(q1 + i) == *(q2 + i))
continue;
else if (*(q1 + i) == *(q2 + i))
return true;
else
return false;
}
return true;
}
void exchange(char *q1,char *q2)
{
int i;
char temp;
for(i=0;i <Max;i++)
{
temp=*(q1+i);
*(q1+i)=*(q2+i);
*(q2+i)=temp;
}
}