4041nofoundGeoge @ 2024-04-16 18:27:54
70分
#include <bits/stdc++.h>
using namespace std;
struct Stu
{
string name;
int id,c,m,e,sum=0;
void read()
{
cin>>name>>c>>m>>e;
sum=c+m+e;
}
// void printt()
// {
// cout<<name<<" "<<c<<" "<<m<<" "<<e<<endl;
// }
}p[10004];
bool cmp(Stu x,Stu y)
{
if(x.sum==y.sum)
{
return x.id>y.id;
}
return x.sum>y.sum;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
p[i].read();
p[i].id=i;
}
sort(p+1,p+n+1,cmp);
cout<<p[1].name<<" "<<p[1].c<<" "<<p[1].m<<" "<<p[1].e;
return 0;
}
by CarrotMeow @ 2024-04-16 18:34:19
return x.id>y.id;
改为 return x.id<y.id;
试下。
by CarrotMeow @ 2024-04-16 18:34:46
id 不应该靠前吗/yiw
by 4041nofoundGeoge @ 2024-04-17 16:26:45
谢谢dalao