武汉科技大学ACM :1007: 华科版C语言程序设计教程(第二版)习题7.10

Problem Description

输入n(n<100)个字符串,每个字符串长度不超过1000,将他们按字典顺序输出。

Input

多组测试样例。 每组第一行有一个整数n表示有n个字符串。 接下来有n行,每行一个字符串。

Output

输出排好序后的字符串,每行输出一个字符串。

Sample Input

3
aba
aab
cab

Sample Output

aab
aba
cab
 1 #include <stdio.h>
 2 #include <string.h>
 3 void sort(char * str[],int size)
 4 {
 5     int i,j;
 6     char * tmp;
 7     for(i=0;i<size-1;i++)
 8     {
 9         for(j=i+1;j<size;j++)
10         {
11             if(strcmp(str[i],str[j])>0)
12             {
13                 tmp=str[i];
14                 str[i]=str[j];
15                 str[j]=tmp;
16             }
17         }
18     }
19 }
20 
21 void main()
22 {
23     char str[100][1000];
24     char * p[100];
25     int i,n;
26     while(scanf("%d",&n)!=EOF)
27     {
28         for(i=0;i<n;i++)
29         {
30             scanf("%s",str[i]);
31             p[i]=str[i];
32         }
33         sort(p,n);
34         for(i=0;i<n;i++)
35             printf("%s
",p[i]);        
36     }
37 }



原文地址:https://www.cnblogs.com/liuwt365/p/4159540.html