Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 struct e 5 { 6 char t[20],name[20]; 7 int s; 8 }p[100005]; 9 int n,c; 10 int cmp1( const void *a,const void *b ) 11 { 12 struct e f1 = *( (e *)a ),f2 = *( ( e * )b ); 13 return strcmp( f1.t,f2.t ); 14 } 15 int cmp2( const void *a,const void *b ) 16 { 17 struct e f1 = *( (e *)a ),f2 = *( ( e * )b ); 18 int t = strcmp( f1.name,f2.name ); 19 if( t ) 20 return t; 21 else 22 return strcmp( f1.t,f2.t ); 23 } 24 int cmp3( const void *a,const void *b ) 25 { 26 struct e f1 = *( (e *)a ),f2 = *( ( e * )b ); 27 int t = f1.s - f2.s; 28 if( t ) 29 return t; 30 else 31 return strcmp( f1.t,f2.t ); 32 } 33 int main( ) 34 { 35 int t = 0; 36 while( scanf( "%d%d",&n,&c ) ,n|c ) 37 { 38 ++t; 39 for( int i = 0; i < n; ++i ) 40 scanf( "%s%s%d",p[i].t,p[i].name,&p[i].s ); 41 if( c == 1 ) 42 qsort( p,n,sizeof( p[0] ),cmp1 ); 43 if( c == 2 ) 44 qsort( p,n,sizeof( p[0] ),cmp2 ); 45 if( c == 3 ) 46 qsort( p,n,sizeof( p[0] ),cmp3 ); 47 printf( "Case %d:\n",t ); 48 for( int i = 0; i < n; ++i ) 49 printf( "%s %s %d\n",p[i].t,p[i].name,p[i].s ); 50 } 51 return 0; 52 }
本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/archive/2012/05/14/2499267.html,如需转载请自行联系原作者