lr0818 @ 2024-10-06 20:28:22
#include <bits/stdc++.h>
using namespace std;
struct s{
int a,e;
long long d;
};
bool cmp(s x, s y) {
if (x.e!=y.e) return x.e>y.e;
if (x.a!=y.a) return x.a>y.a;
return x.d<x.d;
}
int main() {
long long n,b,c;
cin >> n;
for (int i = 1; i <= n; i++) {
cin>>a[i].a>>b>>c;
a[i].d=i;
a[i].e=a[i].a+b+c;
}
sort(a+1,a+n+1,cmp);
for (int i = 1; i <= 5; i++) {
cout<<a[i].d<<" "<<a[i].e<< "\n";
}
return 0;
}
by Grammar__hbw @ 2024-10-06 20:35:13
@lr0818 a数组是什么类型?s类型!下面的代码就可以
#include <bits/stdc++.h>
using namespace std;
const int N=307;
struct s{
int a,e;
long long d;
} a[N];
bool cmp(s x, s y) {
if (x.e!=y.e) return x.e>y.e;
if (x.a!=y.a) return x.a>y.a;
return x.d<y.d;
}
int main() {
long long n,b,c;
cin >> n;
for (int i = 1; i <= n; i++) {
cin>>a[i].a>>b>>c;
a[i].d=i;
a[i].e=a[i].a+b+c;
}
sort(a+1,a+n+1,cmp);
for (int i = 1; i <= 5; i++) {
cout<<a[i].d<<" "<<a[i].e<< "\n";
}
return 0;
}
by Lisuyang @ 2024-10-06 20:35:31
@lr0818
不是,哥们?
return x.d<x.d;
by lr0818 @ 2024-10-06 20:36:52
@Grammar__hbw 谢谢 https://www.luogu.com.cn/record/180555096
by Grammar__hbw @ 2024-10-06 20:37:40
@lr0818 发一条完隐的记录是几个意思qwq
by Grammar__hbw @ 2024-10-06 20:38:36
@lr0818 虽然我用其他方法看到你AC了qwq