BOJ 11650: 좌표 정렬하기, 11651:좌표 정렬하기2

백윤재·2021년 11월 1일
0

BOJ

목록 보기
20/28
post-thumbnail

✔ 문제 링크

BOJ 11650: 좌표 정렬하기


✔ 해결과정

std::pair 사용 연습


✔ 11650: 좌표 정렬하기 정답 Code

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    vector<pair<int,int> > vec;
    cin >> n;
    for(int i=0;i<n;i++) {
        int x, y;
        cin >> x >> y;
        vec.push_back({x, y});
    }

    sort(vec.begin(), vec.end());
    int size = vec.size();
    
    for(int i=0;i<size;i++) {
        cout << vec[i].first << ' ' << vec[i].second << '\n';
    }
}

✔ 11651: 좌표 정렬하기2 정답 Code

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    vector<pair<int,int> > vec;
    cin >> n;
    for(int i=0;i<n;i++) {
        int x, y;
        cin >> x >> y;
        vec.push_back({y, x});
    }

    sort(vec.begin(), vec.end());
    int size = vec.size();
    
    for(int i=0;i<size;i++) {
        cout << vec[i].second << ' ' << vec[i].first << '\n';
    }
}
profile
SKKU 18.5

0개의 댓글