原题:https://www.luogu.com.cn/problem/P1093
这道题用结构体轻轻松松地就可以搞定。
代码如下:
#include<bits/stdc++.h>
using namespace std;
int n;
struct student{
int h,a,b,c,sum;
};//☆☆☆记住这里要写分号!
bool cmp(student n1,student n2){
if(n1.sum < n2.sum)return 0;
else if(n2.sum < n1.sum)return 1;
else if(n1.a < n2.a)return 0;
else if(n1.h > n2.h)return 1;
return 1;
}
int main(){
cin >> n;
student stu[310];
for(int i = 1; i <= n; i++){
cin >> stu[i].a >> stu[i].b >> stu[i].c;
stu[i].h = i;
stu[i].sum = stu[i].a+stu[i].b+stu[i].c;
}
sort(stu + 1,stu + n + 1,cmp);
for(int i = 1; i <= 5; i++)cout << stu[i].h << " " << stu[i].sum << endl;
return 0;
}