字符串排序
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
输入3个字符串,按字典序从小到大进行排序。
Input
输入数据有一行,分别为3个字符串,用空格分隔,每个字符串长度不超过100。
Output
输出排序后的三个字符串,用空格分隔。
Example Input
abcd cdef bcde
Example Output
abcd bcde cdef
Hint
Author
参考代码
#include<stdio.h>
#include<string.h>
void stor_str(char a[][200],int n)
{
int i,j;
char t[200];
for(i = 0; i < n; i++)
{
for(j = 0; j < n - i - 1; j++)
{
if(strcmp(a[j],a[j+1]) > 0)
{
strcpy(t,a[j]);
strcpy(a[j],a[j+1]);
strcpy(a[j+1],t);
}
}
}
}
int main()
{
char s[3][200];
int i;
for(i = 0; i < 3; i++)
{
scanf("%s",s[i]);
}
stor_str(s,3);
for(i = 0; i < 3; i++)
{
printf("%s ",s[i]);
}
return 0;
}