티스토리 뷰

11651번: 좌표 정렬하기 2
https://www.acmicpc.net/problem/11651
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

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

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

	int N = 0;
	cin >> N;

	vector<pair<int, int>> coordinate;

	for (int i = 0; i < N; i++)
	{
		int x = 0;
		int y = 0;
		cin >> x >> y;

		coordinate.push_back(make_pair(x, y));
	}

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

	for (int i = 0; i < N; i++)
	{
		cout << coordinate[i].first << ' ' << coordinate[i].second << '\n';
	}
}
메모리 (KB)시간 (ms)코드 길이 (B)
368848692

Uploaded by N2T

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
링크
Total
Today
Yesterday