90分,有一个在自己的编译器里结果正确,但这里过不了,谁帮我看看
查看原帖
90分,有一个在自己的编译器里结果正确,但这里过不了,谁帮我看看
1610798
wj_M楼主2024/12/21 13:57
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
class Stu
{
public:
	string m_Name;
	int chinese, math, english;
	Stu(string name, int c, int m, int e)
	{
		this->m_Name = name;
		this->chinese = c;
		this->math = m;
		this->english = e;
	}
};
class myGreater
{
public:
	bool operator()(Stu& a, Stu& b)
	{
		int sum1 = a.chinese + a.english + a.math;
		int sum2 = b.chinese + b.english + b.math;
		return sum1 > sum2;
	}
};
int main()
{
	int n;
	cin >> n;

	vector<Stu>v;
	for (int i = 0; i < n; i++)
	{
		string name;
		int a, b, c;
		cin >> name >> a >> b >> c;
		Stu s(name, a, b, c);
		v.push_back(s);
	}
	sort(v.begin(), v.end(), myGreater());
	vector<Stu>::iterator it = v.begin();
	cout << it->m_Name << " " << it->chinese << " " << it->math << " " << it->english;
}
2024/12/21 13:57
加载中...