2007年第4题
题目地址:http://jobdu.sinaapp.com/problem.php?cid=1040&pid=3
C语言源码:
#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct student{char num[10];char name[10];int score;}student;student stu[100010];int cmp1(const void *a,const void *b){student *aa=(student *)a;student *bb=(student *)b;return strcmp(aa->num,bb->num);}int cmp2(const void *a,const void *b){student *aa=(student *)a;student *bb=(student *)b;if(strcmp(aa->name,bb->name)!=0)return strcmp(aa->name,bb->name);elsereturn strcmp(aa->num,bb->num);}int cmp3(const void *a,const void *b){student *aa=(student *)a;student *bb=(student *)b;if(aa->score!=bb->score)return aa->score-bb->score;elsereturn strcmp(aa->num,bb->num);}int main(){int n,c,num,i;scanf("%d %d",&n,&c);num=1;while(n||c){for(i=0;i<n;i++)scanf("%s %s %d",stu[i].num,stu[i].name,&stu[i].score);if(c==1)qsort(stu,n,sizeof(stu[0]),cmp1);elseif(c==2)qsort(stu,n,sizeof(stu[0]),cmp2);elseqsort(stu,n,sizeof(stu[0]),cmp3);printf("Case %d:\n",num++);for(i=0;i<n;i++)printf("%s %s %d\n",stu[i].num,stu[i].name,stu[i].score);scanf("%d %d",&n,&c);}}