Sicily 1738 get ready? (基础题)

链接:http://soj.me/show_problem.php?pid=1738&cid=

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 PC^2 work properly. 
Now, we will give you the information of some contests that are just like the one you are taking. Your task is to output their rank lists according to the contest rules you have already understood.
Input
There is only one number C (<=100) in the first line of the input, which is the number of contests.
For each contest, 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.
Output
For each contest, you should output the rank list (team ID) in descent order in just one line. Numbers separate exactly one space.
Sample Input
 Copy sample input to clipboard
2
3
3 2 200
2 1 100
1 3 300
2
1 2 222
2 1 222
Sample Output
1 3 2
1 2

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <string>
#define MAXN 1005
#define RST(N)memset(N, 0, sizeof(N))
using namespace std;


typedef struct Contest_
{
    int Id;
    int score;
    int time;
}Contest;

Contest N[MAXN];
int n, cas, res;

void Init()
{
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        scanf("%d %d %d", &N[i].Id, &N[i].score, &N[i].time);
    }
    return ;
}

int cmp(const void *a, const void *b)
{
    Contest *p1 = (Contest *)a;
    Contest *p2 = (Contest *)b;
    return p2->score - p1->score;
}

void solve()
{
    qsort(N, n, sizeof(Contest), cmp);
    for(int i=0; i<n; i++) {
        printf("%d", N[i].Id);
        i == n-1 ? printf("\n") : printf(" ");
    }
    return ;
}

int main()
{
    scanf("%d", &cas);
    while(cas--) {
        Init(), solve();
    }
    return 0;
}


你可能感兴趣的:(Sicily 1738 get ready? (基础题))