C语言问题急解

来源:百度知道 编辑:UC知道 时间:2024/05/16 17:10:11
Get Ready?

Time Limit:1000MS Memory Limit:32767K
Total Submit:676 Accepted:253

Description

Is this your first times participating in this kind of contest? I think most of you will answer "YES". So let's do this problem as warm-up and check whether the IMNU-OJ work properly.
Now, we will give you the information of some contest that are just like the one you are taking. Your task is to output their rank lists according to the contes rules you have already understood.

Input

There is only one number C(C≤100) in the first line of the input, which is the number of contest.
For each contes,the first line contains only one number N indicating the total number of teams. And then follow N lines.Each line has three numbers Ti,Si and Pi(1≤Ti≤N,0≤Si≤20,0≤Pi≤10000).which stand for the ID,score and Penalty of the ith team of the contest respectively. Specially, all teams' scores are distinct.

Ou

简单排序问题而已啦~~~

#include<stdio.h>
#include<stdlib.h>
typedef struct {
int id;
int score;
int penalty;
}TM;
TM team[50000];
int cmp(const void *a, const void *b) //qsort的比较函数
{
TM* aa=(TM*)a;
TM* bb=(TM*)b;
if (aa->score!=bb->score) return bb->score-aa->score; //分数不同,分数高的排在前
else return aa->penalty-bb->penalty; //分数相同,罚时少的排在前
}
int main()
{
int C,N;
int i,j;
scanf("%d",&C);
for (i=0; i<C; i++)
{
scanf("%d",&N);
for (j=0; j<N; j++)
scanf("%d%d%d",&team[j].id,&team[j].score,&team[j].penalty);
qsort(team,N,sizeof(team[0]),cmp);
printf("%d",team[0].id);
for (j=1; j<N; j++) printf(" %d",team[j].id);
printf("\n");
}
return 0;
}
===============================================
汗。。。我是写C++,你用C