1 条题解
-
0
最佳小选手 题解
思路
用一个下标
best记录当前最佳选手。比较时先看得分,得分相同时再比较编号。参考代码
#include <bits/stdc++.h> using namespace std; struct Player { int id; string name; int score; }; 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; int best = 0; for (int i = 1; i < n; ++i) { if (a[i].score > a[best].score || (a[i].score == a[best].score && a[i].id < a[best].id)) { best = i; } } cout << a[best].id << ' ' << a[best].name << ' ' << a[best].score << '\n'; return 0; }
信息
- ID
- 5084
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 14
- 已通过
- 4
- 上传者
粤公网安备44195502000195号