Ybocean_s @ 2021-07-09 18:58:38
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct student{
int a,b,c,f;
int z;
} s[301];
bool cmp(student x,student y){
return x.z>y.z;
}
int main()
{
freopen("scholar.in","r",stdin);
freopen("scholar.out","w",stdout);
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>s[i].a>>s[i].b>>s[i].c;
s[i].z=s[i].a+s[i].b+s[i].c;
s[i].f=i;
}
sort(s+1,s+1+n,cmp);
for(int i=1;i<=4;i++){
if(s[i].z==s[i+1].z){
if(s[i+1].a>s[i].a){
swap(s[i],s[i+1]);
}
if(s[i+1].a==s[i].a){
if(s[i+1].f<s[i].f){
swap(s[i],s[i+1]);
}
}
}
}
for(int i=1;i<=5;i++){
cout<<s[i].f<<" "<<s[i].z<<endl;
}
fclose(stdin);fclose(stdout);
return 0;
}
by Waaifu_D @ 2021-07-09 19:00:42
其实你后面乱七八糟的比较都可以塞到cmp里
bool cmp(node a,node b)
{
if(a.ans>b.ans) return 1;
if(a.ans<b.ans) return 0;
if(a.ans==b.ans)
{
if(a.ch>b.ch) return 1;
if(a.ch<b.ch) return 0;
if(a.ch==b.ch)
{
if(a.num>b.num) return 0;
}
}
}
虽然丑但是对
by 月の彼岸 @ 2021-07-09 19:01:21
第八个点吗?
by 月の彼岸 @ 2021-07-09 19:07:54
bool c(x p,x q)
{
if(p.zong==q.zong)
{
return p.yu>=q.yu;
}
return p.zong>q.zong;
}
by 落河之秋 @ 2021-07-09 19:17:18
推荐调一下cmp
bool cmp(Student x,Student y)
{
if(x.Add != y.Add)
{
return x.Add > y.Add;
}
else
{
if(x.Chinese != y.Chinese)
{
return x.Chinese > y.Chinese;
}
else
{
return x.Order < y.Order;
}
}
}