View Code of Problem 82

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<climits>
#include<cmath>
#include<unordered_map>
#include<set>

using namespace std;

struct student
{
	string id;
	string name;
	double grade1;
	double grade2;
	double grade3;
};

bool cmp(student a, student b) {

	return (a.grade1 + a.grade2 + a.grade3 > b.grade1 + b.grade2 + b.grade3);
}

int main()
{
	int n;

	while (cin >> n) {

		int sum1 = 0, sum2 = 0, sum3 = 0;

		vector<student> students;

		for (int i = 0; i < n; i++) {

			student temp;
			cin >> temp.id >> temp.name >> temp.grade1 >> temp.grade2 >> temp.grade3;

			students.push_back(temp);

			sum1 += temp.grade1;
			sum2 += temp.grade2;
			sum3 += temp.grade3;
		}

		sort(students.begin(), students.end(), cmp);

		cout << sum1 / n << " " << sum2 / n << " " << sum3 / n << endl;
		cout << students[0].id << " " << students[0].name << " " << students[0].grade1  << " " << students[0].grade2 << " " << students[0].grade3 << endl;
	}
}

Double click to view unformatted code.


Back to problem 82