sicily 1147.誰拿了最多獎學金

#include <iostream>
#include <memory.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int const N  = 101;

struct student
{
	string name;
	int avscore;//期末平均成績
	int score2;//班級評議成績
	bool isboss;//是否是學生幹部
	bool west;//是否是西部省份學生
	int paper;//發表論文數
	int number;//輸入的次序
	int bonus;//獎金總數
};

bool cmp(student a,student b)
{
	if(a.bonus != b.bonus)
		return a.bonus > b.bonus;
	else
		return a.number < b.number;
}

int main()
{
	int size;
	while(cin >> size && size != 0)
	{
		string name,isboss,west;
		int avscore,score2,paper;
		vector<student> data;
		for(int i = 0;i < size;i++)
		{
			cin >> name >> avscore >> score2 >> isboss >> west >> paper;
			student temp;
			temp.name = name;
			temp.avscore = avscore;
			temp.score2 = score2;
			temp.paper = paper;
			if(isboss == "N")
				temp.isboss = false;
			else
				temp.isboss = true;
			if(west == "N")
				temp.west = false;
			else
				temp.west = true;
			temp.bonus = 0;
			temp.number = i;

			//計算獎學金
			if(temp.avscore > 80 && temp.paper >= 1)
				temp.bonus += 8000;
			if(temp.avscore > 85 && temp.score2 > 80)
				temp.bonus += 4000;
			if(temp.avscore > 90)
				temp.bonus += 2000;
			if(temp.avscore > 85 && temp.west)
				temp.bonus += 1000;
			if(temp.score2 > 80 && temp.isboss)
				temp.bonus += 850;

			data.push_back(temp);
		}

		sort(data.begin(),data.end(),cmp);
		int count = 0;
		for(int i = 0;i < size;i++)
			count += data[i].bonus;

		cout << data[0].name << endl;
		cout << data[0].bonus << endl;
		cout << count << endl;

	}
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章