shuifan @ 2024-10-02 16:59:08
#include<bits/stdc++.h>
using namespace std;
int a[310],b[310],c[310],d[310],h[310],e,f=0,j=0;
int main(){
cin>>e;
for(int i=0;i<=e-1;i++){
cin>>a[i]>>b[i]>>c[i];
d[i]=a[i]+b[i]+c[i];
h[i]=i;
}
for(int i=0;i<=e-1;i++){
for(int j=i+1;j<=e;j++){
if(d[i]>d[j] || (d[i]==d[j] && a[i]>a[j]) || (d[i]==d[j] && a[i]==a[j] && h[i]>h[j])){
swap(d[i],d[j]);
swap(h[i],h[j]);
swap(a[i],a[j]);
}
}
}
for(int i=e;i>=e-4;i--){
cout<<h[i]+1<<" "<<d[i]<<endl;
}
return 0;
}
by ycyxh1 @ 2024-10-02 17:16:39
@shuifan
#include<bits/stdc++.h>
using namespace std;
int a[310],b[310],c[310],d[310],h[310],e,f=0,j=0;
int main(){
cin>>e;
for(int i=0;i<=e-1;i++){
cin>>a[i]>>b[i]>>c[i];
d[i]=a[i]+b[i]+c[i];
h[i]=i;
}
for(int i=0;i<=e-1;i++){
for(int j=i+1;j<=e;j++){
if(d[i]>d[j] || (d[i]==d[j] && a[i]>a[j]) || (d[i]==d[j] && a[i]==a[j] && h[i]<h[j])){
swap(d[i],d[j]);
swap(h[i],h[j]);
swap(a[i],a[j]);
}
}
}
for(int i=e;i>=max(e-4,0);i--){
cout<<h[i]+1<<" "<<d[i]<<endl;
}
return 0;
}
已AC,求关
by shuifan @ 2024-10-02 17:19:57
谢大佬,已关
by shuifan @ 2024-10-02 17:23:27
义父,受我一拜