yun_light @ 2024-10-12 23:11:22
附代码
#include<iostream>
#include<algorithm>
using namespace std;
int n;
struct xue{
int yu,shu,ying;
int hao;
int sum;
}a[301];
bool cmp(xue x,xue y){
if(x.sum!=y.sum) return x.sum>y.sum;
else if(x.sum==y.sum) return x.yu>y.yu;
else if(x.sum==y.sum&&x.yu==y.yu) return x.hao<y.hao;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].yu>>a[i].shu>>a[i].ying;
a[i].sum+=a[i].yu+a[i].shu+a[i].ying;
a[i].hao=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].hao<<" "<<a[i].sum<<endl;
}
return 0;
}
by _Vistion_ @ 2024-10-12 23:39:59
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e9;
const int minn=-1e9;
int n;
struct Node{int c,m,e,fws,xh;}arr[100001];
bool cmp(Node x,Node y){
if(x.fws==y.fws){
if(x.c!=y.c) return x.c>y.c;
else return x.xh<y.xh;
}
else return x.fws>y.fws;
}
signed main(){
ios::sync_with_stdio(false);
//freopen("d.in","r",stdin);
//freopen("d.out","w",stdout);
cin>>n;
for(int i=1; i<=n; i++){
cin>>arr[i].c>>arr[i].m>>arr[i].e;
arr[i].fws=arr[i].c+arr[i].m+arr[i].e;
arr[i].xh=i;
}
stable_sort(arr+1,arr+n+1,cmp);
for(int i=1; i<=5; i++) cout<<arr[i].xh<<' '<<arr[i].fws<<endl;
return 0;
}