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

pair<int, string> member[100001] = {};

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

	int n = 0;
	cin >> n;
	
	for (int i = 0; i < n; ++i)
		cin >> member[i].first >> member[i].second;

	stable_sort(member, member + n, 
		[](pair<int, string> a, pair<int, string> b){
			if (a.first < b.first)
				return true;
			return false;
		});

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

sort() 기존 순서를 보장하지 않고

stable_sort()는 기존 순서를 보장한다.

 

나이가 같을 경우 입력순으로 정렬하기 때문에

stable_sort()를 사용해야 하는 문제

 

 

https://www.acmicpc.net/problem/10814

 

10814번: 나이순 정렬

온라인 저지에 가입한 사람들의 나이와 이름이 가입한 순서대로 주어진다. 이때, 회원들을 나이가 증가하는 순으로, 나이가 같으면 먼저 가입한 사람이 앞에 오는 순서로 정렬하는 프로그램을

www.acmicpc.net