跳到正文

题解

题解:P15929 [TOPC 2021] Olympic Ranking

Echo_qwq约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年3月25日
收录
2026年3月25日
更新
2026年9月15日
篇幅
约 1 分钟
获赞
1
题目
P15929

版本

  1. v2当前
  2. v1

本题核心是根据金牌、银牌、铜牌数量对国家进行排序,规则为:
金牌数多的排名靠前;
金牌数相同,银牌数多的排名靠前;
金银牌数均相同,铜牌数多的排名靠前。
最终输出排名第一的国家名称。
要注意的是:国家名称可能包含空格,不能用普通 cin 读取,需要读取整行。

code

C++
#include<bits/stdc++.h>
using namespace std;
struct coun{
    int g;
    int s;
    int b;
    string q;
}a[305];
bool cmp(coun x,coun y){
    if(x.g!=y.g)return x.g>y.g;
    if(x.s!=y.s)return x.s>y.s;
    return x.b>y.b;
}//将奖牌数量排序
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].g>>a[i].s>>a[i].b;//输入奖牌数量
        getline(cin>>ws,a[i].q);
    }
    sort(a,a+n,cmp);
    cout<<a[0].q;
}

第一篇题解,求通过[滑稽]

原文