Wzq20101105 @ 2023-12-22 12:25:43
#include<bits/stdc++.h>
using namespace std;
int n,a[310],b[310],c[310],d[310],m[3010];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i]>>c[i];
d[i]=a[i]+b[i]+c[i];
m[d[i]]=i;
}
sort(d+1,d+n+1);
for(int i=n;i>=n-4;i--){
cout<<m[d[i]]<<" "<<d[i]<<endl;
}
return 0;
by GXZJQ @ 2023-12-22 12:59:37
@Wzq20101105
用
看一下我的代码吧 :
#include<bits/stdc++.h>
using namespace std;
struct point{
int id;
int yuwen,shuxue,yingyu;
int zongfen;
}a[301];;
int n;
bool cmp(point i,point j){
if(i.zongfen>j.zongfen){
return 1;
}else if(i.zongfen<j.zongfen){
return 0;
}else {
if(i.yuwen>j.yuwen){
return 1;
}else if(i.yuwen<j.yuwen){
return 0;
}else {
return i.id<j.id;
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].yuwen>>a[i].shuxue>>a[i].yingyu;
a[i].zongfen=a[i].yuwen+a[i].shuxue+a[i].yingyu;
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=5;i++){
cout<<a[i].id<<" "<<a[i].zongfen<<endl;
}
return 0;
}
by Wzq20101105 @ 2023-12-22 13:04:52
谢谢大佬解惑。