U E D R , A S I H C RSS

벡터/박능규

~cpp 
#include <iostream> 
#include <vector> 
#include <string>
#include <algorithm>    
#include <functional>   
using namespace std;
struct  student{string name; int score;};
bool compare(student a, student b);
bool compare2(student a, student b);

void main()
{
	student st[5];
	st[0].name = "nj";
	st[0].score = 76;


	st[1].name = "jk";
	st[1].score = 66;

	
	st[2].name = "hj";
	st[2].score = 78;

	st[3].name = "gh";
	st[3].score = 73;

	vector<student> sp;
	sp.push_back(st[1]);
	sp.push_back(st[2]);
	sp.push_back(st[3]);
	sp.push_back(st[4]);
	
	sort(sp.begin(), sp.end(), compare); 
    for(vector<student>::iterator i= sp.begin();i!=sp.end(); i++)   
            cout << i->name <<"\t"<< i->score << endl;
	
	cout << "-------------------------------------"<<endl;
	
	sort(sp.begin(),sp.end(),compare2);
	for(i=sp.begin();i<sp.end();i++)
			cout << i->name<<"\t"<<i->score<< endl;
 
}

bool compare(student a, student b);
{
	return a.name < b.name;
}
bool compare2(student a, student b);		  
{
	return a.score < b.score;	
}
자다가..배꼈는데..에러가있다..난감하다..

STL실습, 블스캠프2004/목요일
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:35
Processing time 0.0080 sec