对字符串排序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char a[100][20],b[20];
    int i,j,n;
 while(scanf("%d",&n)!=EOF)
 {
  for(i=0; i<n; i++)
   scanf("%s",a[i]);
  for (j=0; j<n-1; j++)
  {
   for(i=0; i<n-j; i++)
   {
    if(strcmp(a[i],a[i+1])>0)
    {
     strcpy(b,a[i]);
     strcpy(a[i],a[i+1]);
     strcpy(a[i+1],b);
    }
   }
  }
  for(i=0; i<n; i++)
   printf("%s ",a[i]);
  printf("\n");
 }
    return 0;
}

posted on 2011-05-22 17:01  pcoda  阅读(184)  评论(0编辑  收藏  举报