字符串排序
Problem Description
输入3个字符串,按字典序从小到大进行排序。
Input
输入数据有一行,分别为3个字符串,用空格分隔,每个字符串长度不超过100。
Output
输出排序后的三个字符串,用空格分隔。
Example Input
abcd cdef bcde
Example Output
abcd bcde cdef
代码:
#include <stdio.h>
#include <string.h>
#define MAXN 1000+5
int main()
{
char s[3][MAXN], t[MAXN];
int i, j;
for(i = 0; i < 3; i++)
{
scanf("%s", &s[i]);
}
for(i = 0; i < 2; i++)
{
for(j = i; j < 3; j++)
{
if(strcmp(s[i], s[j]) > 0)
{
strcpy(t, s[i]);
strcpy(s[i], s[j]);
strcpy(s[j], t);
}
}
}
for(i = 0; i < 2; i++)
{
printf("%s ", s[i]);
}
printf("%s", s[2]);
return 0;
}