SXY20121009 @ 2024-11-30 19:19:28
#include <bits/stdc++.h>
using namespace std;
int n;
struct s {
int yw, sx, yy, zf, xh;
}
a[301];
bool cmp(s x, s y) {
if (x.zf != y.zf)
return x.zf > y.zf;
if (x.yw != y.yw)
return x.yw > y.yw;
return y.xh < x.xh;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].yw >> a[i].sx >> a[i].yy;
a[i].zf = a[i].yw + a[i].sx + a[i].yy;
a[i].xh = i;
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= 5; i++) {
cout << a[i].xh << " " << a[i].zf << "\n";
}
return 0;
}
by wangruiqi36 @ 2024-11-30 19:42:36
return y.xh < x.xh;
改成
return x.xh < y.xh;
因为学号越小越靠前
by tujize @ 2024-12-01 21:04:34
你自己看看AC代码:
#include<bits/stdc++.h>
using namespace std;
int n;
struct node{
int c,m,e,id,sum;
};
node a[10005];
bool cmp(node x,node y){
if(x.sum>y.sum) return true;
else if(x.sum<y.sum) return false;
else{
if(x.c>y.c) return true;
else if(x.c<y.c) return false;
else{
return (x.id<y.id);
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].c>>a[i].m>>a[i].e;
a[i].sum=a[i].c+a[i].e+a[i].m;
a[i].id=i;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=5;i++) cout<<a[i].id<<" "<<a[i].sum<<"\n";
return 0;
}