Problem Description
输入3个字符串,按字典序从小到大进行排序。
Input
输入数据有一行,分别为3个字符串,用空格分隔,每个字符串长度不超过100。
Output
输出排序后的三个字符串,用空格分隔。
Sample Input
abcd cdef bcde
Sample Output
abcd bcde cdef
注意:只有三个字符串,比较大小很容易,但做完比较后不能直接让字符串数组作交换,需要借助字符串复制函数strcpy来完成交换
#include <stdio.h>
#include <string.h>
int main()
{
char s1[100],s2[100],s3[100];
char temp[100];
scanf("%s %s %s",s1,s2,s3);
if(strcmp(s1,s2)>0)
{
strcpy(temp,s1);
strcpy(s1,s2);
strcpy(s2,temp);
}
if(strcmp(s2,s3)>0)
{
strcpy(temp,s2);
strcpy(s2,s3);
strcpy(s3,temp);
}
if(strcmp(s1,s2)>0)
{
strcpy(temp,s1);
strcpy(s1,s2);
strcpy(s2,temp);
}
printf("%s %s %s",s1,s2,s3);
return 0;
}