为什么会这样呢?
查看原帖
为什么会这样呢?
1285950
4041nofoundGeoge楼主2024/4/16 18:27

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;
}

2024/4/16 18:27
加载中...