U E D R , A S I H C RSS

벡터/곽세환,조재화

~cpp 
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

struct student {
	string name;
	int score;
};

bool compare(student a, student b);
bool compareName(student a, student b);
void main()
{
	vector<student> vec;
	vector<student>::iterator i;
	student a, b, c, d, e;
	a.name = "재화";
	a.score = 100;
	b.name = "세환";
	b.score = 40;
	c.name = "김군";
	c.score = 30;
	d.name = "이군";
	d.score = 20;
	e.name = "박양";
	e.score = 50;
	
	//cout << a.score;

	vec.push_back(a);
	vec.push_back(b);
	vec.push_back(c);
	vec.push_back(d);
	vec.push_back(e);
	
	sort(vec.begin(), vec.end(), compare);
	for (i = vec.begin(); i < vec.end(); i++)
		cout << i->name << " " << i->score << endl;
	cout<<"------------------------------"<<endl;
	sort(vec.begin(), vec.end(), compareName);
	for (i = vec.begin(); i < vec.end(); i++)
		cout << i->name << " " << i->score << endl;
	
	
	/*for(int i=0; i<vec.size(); i++)
	{
		cout<< (student)vec[i].name << endl;
	}*/
}
bool compare(student a, student b)
{
	return a.name < b.name;
}
bool compareName(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.0119 sec