개발일지/알고리즘

백준 11651번 : 좌표 정렬하기 2

김진우 개발일지 2025. 1. 23. 20:43
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

bool customCompare(const pair<int, int>& a, const pair<int, int>& b)
{
	if (a.second == b.second)
	{
		return a.first < b.first;
	}

	return a.second < b.second;
}

int main()
{
	int N;
	scanf("%d", &N);
	vector<pair<int, int>> points;
	for (int i = 0; i < N; i++)
	{
		pair<int, int> p;
		scanf("%d %d", &p.first, &p.second);
		points.push_back(p);
	}

	sort(points.begin(), points.end(), customCompare);

	for (pair<int, int> p : points)
	{
		printf("%d %d\n", p.first, p.second);
	}

	return 0;
}