Algorithm/Problem Solving 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

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/10825] 국영수  (0) 2020.05.24
[BOJ/10814] 나이순 정렬  (0) 2020.05.22
[BOJ/11650] 좌표 정렬하기  (0) 2020.05.19
[BOJ/2751] 수 정렬하기 2  (0) 2020.05.18
[BOJ/2004] 조합 0의 개수  (0) 2020.05.17
posted by DevMoomin
: