11651번: 좌표 정렬하기 2


#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) |
3688 | 48 | 692 |
Uploaded by N2T