Algorithm/Problem Solving

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

DevMoomin 2020. 5. 21. 23:01

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

- https://www.acmicpc.net/problem/11651

 

사용 알고리즘

- 정렬

 

풀이

 

소스 코드

- https://github.com/moomini/algorithm/blob/master/boj/11651.cpp

#include <cstdio>
#include <vector>
#include <algorithm>
 
using namespace std;
 
bool cmp(const pair<intint> &u, const pair<intint> &v) {
    if (u.second < v.second) return true;
    else if (u.second == v.second) return u.first < v.first;
    else return false;
}
 
int main(void) {
    int n; scanf("%d"&n);
    vector<pair<intint>> v(n);
    for (int i = 0; i < n; ++i) scanf("%d %d"&v[i].first, &v[i].second);
    sort(v.begin(), v.end(), cmp);
    for (int i = 0; i < n; ++i) printf("%d %d\n", v[i].first, v[i].second);
    return 0;
}
cs