{{{~cpp #include #include #include #include #include #include using namespace std; struct Student_info { string name; vector score; int total_score; }; void input_score(vector & students); void calculate_total_score(vector & students); bool compare(const Student_info& student1, const Student_info& student2); void print_students(vector & students); int main() { vector students; input_score(students); calculate_total_score(students); sort(students.begin(),students.end(),compare); print_students(students); return 0; } void input_score(vector & 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 & students) { typedef vector::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 & students) { typedef vector::iterator si_iter; typedef vector::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 <