最终排名 结构体

                                                                                                     最终排名

Description

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

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

Input

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

Output

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

Sample Input

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

Sample Output

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

Hint

 

#include<iostream>
using namespace std;
struct list{
  int id, m;
}team[10000], tmp;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n, i;
        cin>>n;
        for(i=0; i<n; i++)
           cin>>team[i].id>>team[i].m;
        for(i=0; i<n; i++)
          for(int j=n-1; j>i; j--)
          if(team[j].m > team[j-1].m)
          {
              tmp = team[j];
              team[j] = team[j-1];
              team[j-1] = tmp;
          }
        for(i=0; i<n; i++)
          cout<<team[i].id<<" "<<team[i].m<<endl;
    }
return 0;
}


转载于:https://www.cnblogs.com/Genesis2018/p/8304832.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我了解了你的问题。以下是我的回答: 假设有n个参赛者,他们的成功做出题目数分别为s1, s2,...,sn。首先,我们将参赛者按照做出的题目数solved从大到小排序,得到排名r1, r2,...,rn。若有多人成功做出了相同的题目数,我们再按照他们的输入顺序确定排名先后顺序。具实现时,我们可以使用一个map记录每个参赛者成功做出的题目数以及他们的输入顺序。然后,我们对map中的项按照题目数从大到小排序,再按照输入顺序依次输出。 下面是一个示例程序,演示了如何根据输入获取参赛者信息并且按照排名输出参赛者列表: ``` #include <iostream> #include <map> #include <vector> #include <algorithm> using namespace std; // 定义一个结构,表示参赛者 struct Contestant { int solved; // 成功做出的题目数 int order; // 输入顺序 }; // 比较函数,用于map中的排序 bool comp(const pair<int, Contestant>& a, const pair<int, Contestant>& b) { if (a.second.solved != b.second.solved) { return a.second.solved > b.second.solved; } else { return a.second.order < b.second.order; } } int main() { int n; cin >> n; // 用map记录每个参赛者的信息 map<int, Contestant> contestants; for (int i = 1; i <= n; ++i) { int solved; cin >> solved; contestants[i] = {solved, i}; } // 对map中的内容按照排名从大到小排序 vector<pair<int, Contestant>> vec(contestants.begin(), contestants.end()); sort(vec.begin(), vec.end(), comp); // 按照排名输出参赛者列表 for (int i = 0; i < vec.size(); ++i) { cout << vec[i].first << " "; } return 0; } ``` 希望我的回答能够解决你的问题。如果你还有其他问题,请随时向我提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值