题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1862
char id[7];
char name[10];
int score;
}rec[100001];
int cmp1(const void* a,const void* b){//按学号递增排序的比较函数;
return strcmp((*(record *)a).id,(*(record *)b).id);
}
int cmp2(const void* a,const void* b){//按姓名非递减排序的比较函数;
struct record *c=(record *)a;
struct record *d=(record *)b;
if(strcmp(c->name,d->name)!=0){//姓名不相同;
return strcmp(c->name,d->name);
}
else return strcmp(c->id,d->id);
}
int cmp3(const void* a,const void* b){//按成绩非递减排序的比较函数;
struct record *c=(record *)a;
struct record *d=(record *)b;
if(c->score!=d->score){//成绩不相同;
return (c->score-d->score);
}
else return strcmp(c->id,d->id);
}
int main()
{
int N,C,i,cnt=0;
while(scanf("%d %d",&N,&C)!=EOF){
if(N==0)break;
cnt++;
for(i=0;i
getchar();
scanf("%s %s %d",rec[i].id,rec[i].name,&rec[i].score);
}
if(C==1){//按学号递增排序;
qsort(rec,N,sizeof(rec[0]),cmp1);
}
else if(C==2){//按姓名非递减排序;
qsort(rec,N,sizeof(rec[0]),cmp2);
}
else{//按成绩非递减排序;
qsort(rec,N,sizeof(rec[0]),cmp3);
}
printf("Case %d:\n",cnt);
for(i=0;i
int temp;
printf("%s %s %d\n",rec[i].id,rec[i].name,rec[i].score);
}
}
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct record{//学生记录数据结构定义;
}rec[100001];
int cmp1(const void* a,const void* b){//按学号递增排序的比较函数;
}
int cmp2(const void* a,const void* b){//按姓名非递减排序的比较函数;
}
int cmp3(const void* a,const void* b){//按成绩非递减排序的比较函数;
}
int main()
{
}