AcWing 429. 奖学金
原题链接
简单
作者:
回头不是从前
,
2021-01-17 14:31:56
,
所有人可见
,
阅读 446
(关键字排序)
#include<iostream>
#include<algorithm>
using namespace std;
struct stu{
int no;
int Chinese;
int math;
int English;
int total;
}stus[310];
bool cmp(const stu a, const stu b) {
if(a.total != b.total) return a.total > b.total;
else {
if(a.Chinese != b.Chinese) return a.Chinese > b.Chinese;
else return a.no < b.no;
}
}
int main() {
int n;
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> stus[i - 1].Chinese >> stus[i - 1].math >> stus[i - 1].English;
stus[i - 1].no = i;
stus[i - 1].total = stus[i - 1].Chinese + stus[i - 1].math + stus[i - 1].English;
}
sort(stus, stus + n, cmp);
for(int i = 0; i < 5; ++i) cout << stus[i].no << ' ' << stus[i].total << endl;
return 0;
}