Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

벡터/권정욱

From ZeroWiki
Revision as of 00:44, 27 March 2026 by Maintenance script (talk | contribs) (Repair batch-0005 pages from live compare)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

벡터/권정욱

데블스캠프/목요일/스튜던트 정렬하기

#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.score>b.score;
}

int main(){
	student student_num1;
	student student_num2;
	student student_num3;
	student student_num4;
	student student_num5;
	student_num1.name = "Park Jin-young";
	student_num1.score = 80;
	student_num2.name = "Kwon Jung-wook";
	student_num2.score = 100;
	student_num3.name = "Lee Jae-hwan";
	student_num3.score = 80;
	student_num4.name = "Kim Su-jin";
	student_num4.score = 70;
	student_num5.name = "Kim Hong-bem";
	student_num5.score = 90;

	vector<student> vec;
	vec.push_back(student_num1);
	vec.push_back(student_num2);
	vec.push_back(student_num3);
	vec.push_back(student_num4);
	vec.push_back(student_num5);

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

	vector<student>::iterator i=vec.begin(); 	
	for(i = vec.begin(); i != vec.end(); i++) 
	{ 
		cout << (*i).name << "의 성적은 : " << (*i).score << endl;
	} 

	return 0;
}

STL실습