#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> //sort
#include <numeric> //accumulate
using namespace std;
typedef struct student_table_struct {
string name;
vector<int> score;
unsigned int total;
double avg;
} student_type;
void readdata(vector<student_type>& ztable); //
bool zcompare(const student_type ele1, const student_type ele2); //sort 교
void printdata(vector<student_type>& ztable); //
void operation(vector<student_type>& ztable); //과 균
int main()
{
vector<student_type> ztable;
// .
readdata(ztable);
//과 균
operation(ztable);
//균
sort(ztable.begin(),ztable.end(),zcompare);
//
printdata(ztable);
return 0;
}
//
void readdata(vector<student_type>& ztable){
ifstream fin("data.txt");
student_type tmp;
int tmp2,i;
while(1)
{
fin >> tmp.name;
for(i=1;i<=4;i++)
{
fin >> tmp2;
tmp.score.push_back(tmp2);
}
if(fin.eof()) break;
ztable.push_back(tmp);
}
}
//sort 교
bool zcompare(const student_type ele1, const student_type ele2)
{
return ele1.avg > ele2.avg;
}
//기
void printdata(vector<student_type>& ztable)
{
int cnt=0;
cout << "\t국\t\t\t과\t\t균" << endl;
for(vector<student_type>::iterator i=ztable.begin();i<ztable.end();++i)
{
cout << i->name << "\t" <<
i->score[cnt*4+0] << "\t" <<
i->score[cnt*4+1] << "\t" <<
i->score[cnt*4+2] << "\t" <<
i->score[cnt*4+3] << "\t" <<
i->total << "\t" <<
i->avg <<endl;
cnt++;
}
}
void operation(vector<student_type>& ztable)
{
for(vector<student_type>::iterator i=ztable.begin() ;i<ztable.end();++i)
{
i->total = accumulate(i->score.begin()+i->score.size()-4,i->score.end(),0);
i->avg = i->total/4.0;
}
}