Posted on 2009-03-13 20:02
Hero 阅读(118)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 // 1154 Accepted 0 88 790 C++
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 const int size = 120 ;
8 struct NODE
9 {
10 char str[100] ;
11 int len ;
12 };
13 struct NODE node[size] ;
14
15 int inn ;
16
17 int cmp( const void *a, const void *b )
18 {
19 struct NODE *c = (struct NODE *)a ;
20 struct NODE *d = (struct NODE *)b ;
21
22 if( c->len != d->len )
23 return c->len - d->len ;
24 else
25 return strcmp( c->str, d->str ) ;
26 }
27
28 int main()
29 {
30 while( scanf( "%d", &inn ) != EOF && inn )
31 {
32 char instr[100] ; int strval = 0 ;
33 for( int i=1; i<=inn; i++ )
34 {
35 scanf( "%s", node[i].str ) ;
36 node[i].len = strlen( node[i].str ) ;
37 }
38
39 qsort( node+1, inn, sizeof(node[1]), cmp ) ;
40
41 for( int i=1; i<=inn; i++ )
42 {
43 printf( "%s\n", node[i].str ) ;
44 }
45 printf( "\n" ) ;
46 }
47
48 return 0 ;
49 }