View Code of Problem 82

#include<bits/stdc++.h>
using namespace std;
struct stud{
	int gradeA,gradeB,gradeC;
	string id,s;
	int ave;
};
bool cmp(stud,stud);
int main(){
	int n;
	cin>>n;
	stud stu[1000];
	int A = 0,B = 0,C = 0;
	for(int i = 0;i<n;i++){
		cin>>stu[i].id>>stu[i].s>>stu[i].gradeA>>stu[i].gradeB>>stu[i].gradeC;
		stu[i].ave = (stu[i].gradeA+stu[i].gradeB+stu[i].gradeC)/3;
		A += stu[i].gradeA;
		B += stu[i].gradeB;
		C += stu[i].gradeC;
	}
	cout<<A/n<<" "<<B/n<<" "<<C/n;
	cout<<endl;
	sort(stu,stu+n,cmp);	
		cout<<stu[0].id<<" "<<stu[0].s<<" "<<stu[0].gradeA<<" "<<stu[0].gradeB<<" "<<stu[0].gradeC;
	return 0;
}
bool cmp(stud a,stud b){
	return a.ave>b.ave;
}

Double click to view unformatted code.


Back to problem 82