[BOJ]11651-좌표 정렬하기 2

yoon_H·2024년 9월 14일

BOJ

목록 보기
94/110

11651

성공코드

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

vector<pair<int, int>> vec;

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

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

	int N;
	
	cin >> N;

	for (int i = 1; i <= N; i++)
	{
		int x, y;
		cin >> x >> y;
		
		vec.push_back(make_pair(x, y));
	}

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

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

0개의 댓글