第2个回答 2012-05-25
#include<stdio.h>
#include<string.h>
#define N 4
void sort(char s[N][2*N])
{
int i,j;
char swap[2*N];
for(i=N-1;i>=0;i--)
for(j=0;j<i;j++)
{
if(strcmp(s[j],s[j+1])>0)
{
strcpy(swap,s[j]);
strcpy(s[j],s[j+1]);
strcpy(s[j+1],swap);
}
}
}
int main()
{
char buf[N][2*N];
int i;
for(i=0;i<N;i++)
{
puts("input a string:");
scanf("%s",buf[i]);
}
sort(buf);
for(i=0;i<N;i++)
printf("%s\n",buf[i]);
return 0;
}