0
点赞
收藏
分享

微信扫一扫

F - 最终排名

一脸伟人痣 2022-02-22 阅读 44

Description

第四届山东理工大学ACM网络编程擂台赛比赛完后需要产生一个最终排名,排名按照题数多少来决定。但是有太多的队伍参与,手动计算排名已经不能满足比赛的需求。现在有一份名单记录各个队伍的ID和做出的题目数,需要你写一个程序,产生最终的排名。

为了简化题目,这里的排名规则为:做出题目数量多的队伍排在前面,如果题数相等,保持输入时的相对顺序不要改变。

Input

单组输入。第一行有一个正整数N(1 < N ≤ 10000),表示队伍数量。接下来N 行包含两个整数,1 ≤ ID ≤ 10^7, 0 ≤ M ≤ 100。ID为队伍的编号,M为做出的题数。

Output

每组数据输出包含N行,第i行有两个整数,ID和M表示排在第i位的队伍的ID和做出的题数。

Sample

Input

8
1 2
16 3
11 2
20 3
3 5
26 4
7 1
22 4

Output

3 5
26 4
22 4
16 3
20 3
1 2
11 2
7 1
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

struct team{
    int id;
    int num;}tea[10000] = {0, 0};

int main(){
    int n, i, j, temp;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d %d", &tea[i].id, &tea[i].num);
    }

    for(i = 0; i < n - 1; i++){
        for(j = 0; j < n - 1 - i; j++){
            if(tea[j].num < tea[j + 1].num){
                temp = tea[j].num;
                tea[j].num = tea[j + 1].num;
                tea[j + 1].num = temp;

                temp = tea[j].id;
                tea[j].id = tea[j + 1].id;
                tea[j + 1].id = temp;
            }
        }
    }
    for(i = 0; i < n; i++){
        printf("%d %d\n", tea[i].id, tea[i].num);
    }
    return 0;
}

举报

相关推荐

博客排名

MySQL排名

蓝桥杯——最终章

java lsit排名

班级排名 0052

C++ 排名

0 条评论