~cpp 
#include <iostream>
#include <fstream>
#include <string> 
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std; 

struct Student_info
{
	string name;
	vector<int> score;
	int total_score;
};

void input_score(vector<Student_info> & students);
void calculate_total_score(vector<Student_info> & students);
bool compare(const Student_info& student1, const Student_info& student2);
void print_students(vector<Student_info> & students);
 
int main() 
{ 
    vector<Student_info> students;
    input_score(students);
	calculate_total_score(students);
	sort(students.begin(),students.end(),compare);
	print_students(students);
	return 0; 
} 


void input_score(vector<Student_info> & students)
{
	Student_info temp;
	ifstream fin("input.txt"); // fin과 input.txt를 연결  
    //ofstream fout("output.txt"); // fout과 output.txt를 연결 
	
	string name;
	int score;
	fin >> name >> name >> name >> name >> name;
	while(fin >> name)
	{
		temp.name = name;
		while(fin >> score)
			temp.score.push_back(score);
		students.push_back(temp);
		temp.score.erase(temp.score.begin(),temp.score.end());
		fin.clear();	
	}
    //fin >> a >> b; // cin으로 화면에서 입력받는다면, fin은 연결된 파일로부터 입력받는다. 
    //fout << a+b << endl; // cout으로 화면으로 출력한다면, fout은 연결된 output.txt에 a+b를 출력

}

void calculate_total_score(vector<Student_info> & students)
{
	typedef vector<Student_info>::iterator iter;
	for(iter i = students.begin(); i != students.end(); i++)
		i->total_score = accumulate(i->score.begin(),i->score.end(),0);
}

bool compare(const Student_info& student1, const Student_info& student2)
{
	return student1.total_score > student2.total_score;	
}

void print_students(vector<Student_info> & students)
{
	typedef vector<Student_info>::iterator si_iter;
	typedef vector<int>::iterator int_iter;
	for(si_iter i = students.begin(); i != students.end(); i++)
	{
		cout << i->name << " ";
		for(int_iter j = i->score.begin(); j != i->score.end(); j++)
			cout << *j << " ";			
		cout << i->total_score << " " << i->total_score/4 <<endl;
	}
}

마지막에 주석 처리한거 왜 에러나는거징..ㅡㅜ
오타가 아닐까? ㅡ.ㅡ socre ? - eternalbleu
ㅡㅜ...쩝 - 상섭
Retrieved from http://wiki.zeropage.org/wiki.php/CPPStudy_2005_1/STL성적처리_4
last modified 2021-02-07 05:22:42