U E D R , A S I H C RSS

벡터/김태훈

No older revisions available

No older revisions available



~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 = "build";
	st[0].score = 48;

	st[1].name = "deb";
	st[1].score = 57;

	st[2].name = "finde";
	st[2].score = 87;

	st[3].name = "inew";
	st[3].score = 90;

	st[4].name = "ilbo";
	st[4].score = 82;

	vector <student> stre;
	stre.push_back(st[0]);
	stre.push_back(st[1]);
	stre.push_back(st[2]);
	stre.push_back(st[3]);
	stre.push_back(st[4]);

	sort(stre.begin(), stre.end(),compare);
	for(vector<student>::iterator i = stre.begin(); i!=stre.end() ;i++)
		cout << i->name <<"\t"<<i->score<< endl;

	cout<<"-------------------------"<<endl;
	sort(stre.begin(), stre.end(),compare2 );
	
	for(i = stre.begin();i<stre.end();i++)
		cout << i->name <<"\t"<<i->score<< endl;
	
	
	/*
	for(vector<student>::iterator i = stre.begin();!(i=stre.end());i++)
		cout << (*i).name << 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:36
Processing time 0.0287 sec