링크 : https://www.acmicpc.net/problem/11651
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool compare(pair<int, int>a, pair<int, int>b) {
	if (a.second == b.second) {
		return a.first < b.first;
	}
	else {
		return a.second < b.second;
	}
}
int main(){
    int n = 0; 
    cin >> n;
    
    vector<pair<int, int>> v;
    for(int i = 0; i < n; i++){
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        v.push_back(make_pair(tmp1, tmp2));
    }
    sort(v.begin(), v.end(), compare);
    
    for(auto it = v.begin(); it != v.end(); it++)
        cout << it->first << " " << it->second << '\n';
    
    return 0;
}