[백준] 10814 나이순 정렬

0

백준

목록 보기
177/271
post-thumbnail

[백준] 10814 나이순 정렬

#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
using namespace std;

bool cmp(pair<int, string>a, pair<int, string> b){
	return a.first < b.first;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int n;
	cin >> n;

	vector<pair<int, string>> vec;
	for (int i = 0; i < n; ++i) {
		int age;
		string name;
		cin >> age >> name;
		vec.push_back({ age, name });
	}
	stable_sort(vec.begin(), vec.end(), cmp);

	for (int i = 0; i < n; ++i) {
		cout << vec[i].first << " " << vec[i].second << "\n";
	}

	return 0;
}
profile
Be able to be vulnerable, in search of truth

0개의 댓글