码迷,mamicode.com
首页 > 其他好文 > 详细

PKU 百炼OJ 奖学金

时间:2018-12-30 23:22:59      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:main   temp   pst   back   tor   push   chinese   turn   return   

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 奖学金

标签:main   temp   pst   back   tor   push   chinese   turn   return   

原文地址:https://www.cnblogs.com/tangmiao/p/10200987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!