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);
int main()
{

	student DarkLJY;
	student B;
	student C;
	student D;


	DarkLJY.name = "juyoung";
	B.name = "gogogo";
	C.name = "hahaha";
	D.name = "good";
	

	DarkLJY.score = 50;
	B.score = 70;
	C.score = 80;
	D.score =90;


	
	 vector < student > vec; 
          vec.push_back(DarkLJY); 
	 vec.push_back(B); 
	 vec.push_back(C); 
	 vec.push_back(D); 


	 vector < student > vec;
     vec.push_back(DarkLJY);
	 vec.push_back(B);




 	sort(vec.begin(),vec.end(),compare);

	for(int j=0;j<2;j++)
	{
		cout << vec[j].score << "  ";
	}
	cout <<  endl;


	return 0;
}
bool compare(student a, student b)
{
	return a.score > b.score ; // 부등호의 방향에 따라 오름차순 내림차순 결정
}


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

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.1134 sec