Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12595 Accepted Submission(s): 4955
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 const int maxn=100010; 5 struct student 6 { 7 char no[12]; 8 char name[12]; 9 int score; 10 }; 11 student sta[maxn]; 12 int cmp1(const void *a ,const void *b) /*< 学号排序 >*/ 13 { 14 return strcmp((*(student*)a).no,(*(student*)b).no); /* <升序> */ 15 } 16 int cmp2(const void *a ,const void *b) /* <升序> */ 17 { 18 19 if(strcmp((*(student *)a).name , (*(student *)b).name )==0) 20 return strcmp((*(student *)a).no,(*(student *)b).no); /* <升序> */ 21 else return strcmp((*(student *)a).name , (*(student *)b).name ); 22 } 23 24 int cmp3(const void *a ,const void *b) 25 { 26 27 if((*(student *)a).score ==(*(student *)b).score) return strcmp((*(student *)a).no,(*(student *)b).no); /* <升序> */ 28 else return (*(student *)a).score -(*(student *)b).score ; 29 } 30 31 int main() 32 { 33 34 int n,c,i,cnt=1; 35 //freopen("test.in","r",stdin); 36 //freopen("test.out","w",stdout); 37 while(scanf("%d%d",&n,&c),n) 38 { 39 memset(sta,0,sizeof(sta)); 40 for(i=0;i<n;i++) 41 scanf("%s%s%d",sta[i].no,sta[i].name,&sta[i].score); 42 switch(c) 43 { 44 case 1: qsort(sta,n,sizeof(sta[0]),cmp1); break; 45 case 2: qsort(sta,n,sizeof(sta[0]),cmp2); break; 46 case 3: qsort(sta,n,sizeof(sta[0]),cmp3); break; 47 } 48 printf("Case %d:\n",cnt++); 49 for(i=0;i<n ;i++) 50 printf("%s %s %d\n",sta[i].no,sta[i].name,sta[i].score); 51 } 52 return 0; 53 }