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;
	
	student()
	{
		
	}
	student(string aName, int aScore)      // 생성자 ?? !! 
	{
		name = aName;
		score = aScore;
	}
};

bool comp_score(student a, student b);
bool comp_name(student a, student b);

void main()
{
	student students[5] = {
		student("황선홍",94),
		student("홍명보",95),
		student("김태영",93),
		student("최용수",87),
		student("안정환",98),
	};

	vector<student> vector1;
	
	for(int i=0; i<5; i++)
		vector1.push_back(students[i]);
	
	sort(vector1.begin(), vector1.end(), comp_score);

	for(i=0; i<5; i++)
		cout << vector1[i].score << endl ;

	sort(vector1.begin(), vector1.end(), comp_name);

	for(vector<student>::iterator j=vector1.begin(); j<vector1.end(); j++)
		cout << (*j).name << endl ;

}

bool comp_score(student a, student b)
{
	return a.score < b.score;
}

bool comp_name(student a, student b)
{
	return a.name < b.name;
}

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