View Code of Problem 82

#include<bits/stdc++.h>
using namespace std;
struct Student{
	char number;
	string name;
	double g1;
	double g2;
	double g3;
	int sum;
};
bool comp(Student lhs,Student rhs){
	return lhs.sum > rhs.sum ;
}
Student a[10000];
int main(){
	int N;
	double tog1=0,tog2=0,tog3=0;
	while(cin>>N){
		for(int i=0;i<N;i++){
			cin>>a[i].number>>a[i].name>>a[i].g1>>a[i].g2>>a[i].g3;
			tog1+=a[i].g1;tog2+=a[i].g2;tog3+=a[i].g3;
			a[i].sum=a[i].g1+a[i].g2+a[i].g3;
		}
		sort(a,a+N,comp);
		double av1,av2,av3;
		av1=tog1/N;av2=tog2/N;av3=tog3/N;
		printf("%.0lf %.0lf %.0lf\n",av1,av2,av3);
		printf("%c %s %.0lf %.0lf %.0lf",a[0].number,a[0].name.c_str(),a[0].g1,a[0].g2,a[0].g3);
	}
}

Double click to view unformatted code.


Back to problem 82