U E D R , A S I H C RSS

벡터/김홍선,노수민

백터 연습문제

~cpp 
#include <iostream> 
#include <fstream> 
#include <string> 
#include <vector> 
#include <algorithm> 
using namespace std; 
 
struct student 
{ 
        string name; 
        int score; 
}; 
 
bool compare(student stu1, student stu2) 
{ 
        return stu1.score > stu2.score; 
} 
 
void main() 
{ 
        ifstream fin("input.txt"); 
        vector <student> vec; 
        vector <student> ::iterator i=0; 
        student temp; 
 
        while(!fin.eof()) 
        { 
 
                fin >> temp.name >> temp.score;  
                vec.push_back(temp); 
        } 
         
        sort(vec.begin(), vec.end(), *compare); 
 
        for(i=vec.begin();i<vec.end();i++) 
        { 
        cout << (*i).name << endl; 
        cout << (*i).score << endl; 
    } 
} 

STL실습, 블스캠프2004/목요일


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:35
Processing time 0.0079 sec