본문 바로가기
Algorithm 🧑🏻‍💻/백준(BOJ)

[백준,c++] 11650번 - 좌표 정렬하기

by dkswnkk 2021. 10. 28.
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool cmp(pair<int,int> a, pair<int,int> b) {
    if (a.first != b.first) return a.first < b.first;
    else return    a.second < b.second;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N; cin >> N;
    vector<pair<int, int>>v;
    while (N--) {
        int x, y; cin >> x >> y;
        v.push_back({ x,y });
    }
    sort(v.begin(), v.end(), cmp);
    for (int i = 0; i < v.size(); i++) {
        cout << v[i].first << ' ' << v[i].second << "\n";
    }
}

댓글