[[TableOfContents]] = Info = {{|ìž‘ì„±ì¼ : 2005 08 03 ìˆ˜ì •íšŒìˆ˜ : 0회 구현특ì´ì‚¬í• 미구현부분 |}} = Input Text = {{{ ê¹€ì² ìˆ˜ 59 98 75 91 마ë™íƒ 66 78 77 84 ë°•ë¯¼ì² 52 50 63 72 ì‹ ìˆœì´ 97 55 52 97 송ì˜ì´ 78 82 63 73 양민수 72 66 73 52 장준구 95 62 94 53 최호민 78 53 74 75 태ì„호 66 82 82 94 í•œë…¸ë¼ 86 65 62 68 }}} = Code = {{{ #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; } } }}} = Result = {{{ ì´ë¦„ êµì–´ ì˜ì–´ 수학 과학 ì´ì í‰ê· 태ì„호 59 98 75 91 324 81 ê¹€ì² ìˆ˜ 66 78 77 84 323 80.75 마ë™íƒ 52 50 63 72 305 76.25 장준구 97 55 52 97 304 76 ì‹ ìˆœì´ 78 82 63 73 301 75.25 송ì˜ì´ 78 53 74 75 296 74 í•œë…¸ë¼ 66 82 82 94 281 70.25 최호민 72 66 73 52 280 70 양민수 95 62 94 53 263 65.75 ë°•ë¯¼ì² 86 65 62 68 237 59.25 ress any key to continue }}} = Idle Talk = í¡ ì–´ë ¤ì›Œë”° ã… ã… ---- [CPPStudy_2005_1]