1 条题解
-
0
选手成绩排名 题解
思路
把“一个选手的所有信息”作为一个整体参与排序。比较函数先比较
score,只有得分相同时才比较id。参考代码
#include <bits/stdc++.h> using namespace std; struct Player { int id; string name; int score; }; bool cmp(const Player &a, const Player &b) { if (a.score != b.score) return a.score > b.score; return a.id < b.id; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<Player> a(n); for (auto &p : a) cin >> p.id >> p.name >> p.score; sort(a.begin(), a.end(), cmp); for (const auto &p : a) { cout << p.id << ' ' << p.name << ' ' << p.score << '\n'; } return 0; }
- 1
信息
- ID
- 5085
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 17
- 已通过
- 4
- 上传者
粤公网安备44195502000195号