排序问题
排序 并记录每个坐标例如:score[0]=63;
score[1]=19;
score[2]=39;
假设score为学生的分数 下标为学生号 怎样输出学生的排名啊?
本例应为:1 3 2
多谢解疑!!!

程序代码:#include <stdio.h>
#include <stdlib.h>
#define LEN 10
typedef struct student
{
double score;
int number;
}STU;
int mycomp(const void *p1, const void *p2);
int main(void)
{
STU a[LEN];
int i;
for (i = 0; i < LEN; i++)
{
a[i].number = i + 1;
printf("输入学号%d学生的成绩:",a[i].number);
scanf("%lf", &a[i].score);
}
qsort(a, LEN, sizeof(STU), mycomp); //快排
printf("排名\t学号\t分数\n");
for (i = 0; i < LEN; i++)
{
printf("%d\t%d\t%lf\n",i+1,a[i].number,a[i].score);
}
return 0;
}
int mycomp(const void *p1, const void *p2)
{
const STU * a = (const STU *)p1;
const STU * b = (const STU *)p2;
if (a->score < b->score)
{
return 1;
}
else if (a->score == b->score)
{
return 0;
}
else
return -1;
}