文章
3
粉丝
56
获赞
3
访问
1.8k
如果坚持使用qsort,就在结构体里另加一标记记录出现顺序,成绩相同时按顺序排序。
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char name[50];
int score;
int id;
} Student;
int cmp1(const int *a,const int *b)
{
Student* ia=(Student*)a;
Student* ib=(Student*)b;
if(ia->score==ib->score)return (ia->id>ib->id);
else return ia->score>ib->score;
}
int cmp2(const int *a,const int *b)
{
Student* ia=(Student*)a;
Student* ib=(Student*)b;
if(ia->score==ib->score)return (ia->id>ib->id);
else return ia->score<ib->score;
}
int main()
{
int n,order;
while(scanf("%d",&n)!=EOF)
{
Student students[n];
scanf("%d",&o...
登录后发布评论
暂无评论,来抢沙发