PKU 百炼OJ 奖学金

Posted tangmiao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PKU 百炼OJ 奖学金相关的知识,希望对你有一定的参考价值。

http://bailian.openjudge.cn/ss2017/A/

#include<iostream>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
struct Student
{
	int num;
	int chinese;
	int math;
	int english;
	int getAllGrade()
	{
		return chinese + math + english;
	}
};
bool compare(Student one, Student two)
{
	int allGradeOne = one.getAllGrade();
	int allGradeTwo = two.getAllGrade();
	if (allGradeOne>allGradeTwo)
	{
		return true;
	}
	else if(allGradeOne==allGradeTwo)
	{
		if (one.chinese>two.chinese)
		{
			return true;
		}
		else if (one.chinese==two.chinese)
		{
			if (one.num<two.num)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
int main()
{
	int n = 0;
	std::cin >> n;
	std::vector<Student> students;
	int cnt = 1;
	for (; cnt <= n; cnt++)
	{
		Student tempStudent;
		tempStudent.num = cnt;
		int tempChinese = 0, tempMath = 0, tempEnglish = 0;
		std::cin >> tempChinese >> tempMath >> tempEnglish;
		tempStudent.chinese = tempChinese;
		tempStudent.math = tempMath;
		tempStudent.english = tempEnglish;
		students.push_back(tempStudent);
	}
	/*for (auto tempStudent : students)
	{
		std::cout << tempStudent.num << ":" << tempStudent.chinese << std::endl;
	}*/
	sort(students.begin(), students.end(), compare);
	for (int i = 0; i < 5; i++)
	{
		std::cout << students[i].num << " " << students[i].getAllGrade() << std::endl;
	}
	return 0;
}

  

以上是关于PKU 百炼OJ 奖学金的主要内容,如果未能解决你的问题,请参考以下文章

PKU 百练OJ Arbitrage

PKU OJ A Bug's life

pku_oj: W11-02熄灯问题(C++)

pku_oj: w11-03讨厌的青蛙(C++枚举算法)

pku_oj: 1681Painter's Problem(画家问题)(C++)

求像北大百练POJ那样的提供程序设计题目的网站的网址,最好是中文的