字符串排序
Time Limit: 1000 ms / Memory Limit: 65536 kb
Description
输入3个字符串,按字典序从小到大进行排序。
Input
输入数据有一行,分别为3个字符串,用空格分隔,每个字符串长度不超过100。
Output
输出排序后的三个字符串,用空格分隔。
Sample Input
abcd cdef bcde
Sample Output
abcd bcde cdef
Source
Submit
#include<stdio.h>
#include<string.h>
int main()
{
char a[101] = {NULL}, b[101] = { NULL }, c[101] = { NULL }, d[101] = { NULL };
scanf("%s", &a);
getchar();
scanf("%s", &b);
getchar();
scanf("%s", &c);
if (strcmp(a, b) > 0)
{
strcpy(d, a);
strcpy(a, b);
strcpy(b, d);
}
if (strcmp(a, c) > 0)
{
strcpy(d, a);
strcpy(a, c);
strcpy(c, d);
}
if (strcmp(b, c) > 0)
{
strcpy(d, c);
strcpy(c, b);
strcpy(b, d);
}
printf("%s ", a); printf("%s ", b); printf("%s ", c);
return 0;
}