题解 第三章排序与查找| #成绩排序#
成绩排序
http://www.nowcoder.com/practice/3f27a0a5a59643a8abf0140b9a8cf1f7
#include <stdio.h>
#include <stdlib.h>
typedef struct Grade
{
int Order;
int Point;
}Grade;
int cmp(const void *a,const void *b)
{
if(((Grade*)a)->Point==((Grade*)b)->Point)
return ((Grade*)a)->Order>((Grade*)b)->Order;
return ((Grade*)a)->Point>((Grade*)b)->Point;
}
int main()
{
int Num;
scanf("%d",&Num);
Grade G[Num];
for(int i=0;i<Num;i++)
{
scanf("%d%d",&G[i].Order,&G[i].Point);
}
//以上将所有数据录入
qsort(G,Num,sizeof(Grade),cmp);
for(int i=0;i<Num;i++)
printf("%d %d\n",G[i].Order,G[i].Point);
return 0;
}
王道机试指南刷题 文章被收录于专栏
计划刷完这本书