U E D R , A S I H C RSS

벡터/조동영

연습문제


~cpp 
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct student
{
	string name;
	int score;
};
bool compare(student a, student b)
{
	return a.name>b.name;
}
int main()
{
	student boy1;
	boy1.name = "a";
	boy1.score = 90;
	student boy2;
	boy2.name ="b";
	boy2.score=80;
	student boy3;
	boy3.name="c";
	boy3.score=65;
	student boy4;
	boy4.name="d";
	boy4.score=89;
	student boy5;
	boy5.name="e";
	boy5.score=23;
	


	vector <student> vec;
	vec.push_back(boy1);
	vec.push_back(boy2);
	vec.push_back(boy3);
	vec.push_back(boy4);
	vec.push_back(boy5);
	
	sort(vec.begin(),vec.end(), compare);
	
	vector<student>::iterator i=vec.begin(); 
	for(i=vec.begin();i!=vec.end();i++) 
	{ 
		cout<<(*i).score<<endl;
	}

STL실습, 블스캠프2004/목요일
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0879 sec