题意
给定若干学生的姓名、学号、成绩,按成绩排序,输出最好的最差的人的姓名和学号。
思路
数据结构排序题。tuple+sort即可。
代码
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
while (cin >> n) {
vector<tuple<int, string, string>> stu;
for (int i = 0; i < n; ++i) {
string name, id;
int score;
cin >> name >> id >> score;
stu.emplace_back(score, name, id);
}
sort(stu.begin(), stu.end());
auto maxn = *stu.begin();
auto minn = *--stu.end();
cout << get<1>(minn) << ' ' << get<2>(minn) << '\n';
cout << get<1>(maxn) << ' ' << get<2>(maxn) << '\n';
}
return 0;
}
HINT
不定时更新更多题解,Basic Level 全部AC代码,详见 link ! ! !