Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
输入3个字符串,按字典序从小到大进行排序。
Input
输入数据有一行,分别为3个字符串,用空格分隔,每个字符串长度不超过100。
Output
输出排序后的三个字符串,用空格分隔。
Sample Input
abcd cdef bcde
Sample Output
abcd bcde cdef
Hint
Source
本题可以考虑三个整数排序的方法,只是在交换时用strcpy实现
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char a[101],b[101],c[101],s[101];
scanf("%s%s%s",a,b,c);
if(strcmp(a,b)>0)
{
strcpy(s,a);
strcpy(a,b);
strcpy(b,s);
}
if(strcmp(a,c)>0)
{
strcpy(s,a);
strcpy(a,c);
strcpy(c,s);
}
if(strcmp(b,c)>0)
{
strcpy(s,b);
strcpy(b,c);
strcpy(c,s);
}
printf("%s %s %s",a,b,c);
return 0;
}