11651_좌표 정렬하기 2

bgy·2022년 1월 3일
0

백준

목록 보기
11/21

시간 초과나면 scanf와 printf 사용해보기
2쌍의 값을 묶고 싶다면 pair 헤더 : #include <utility>
3쌍의 값을 묶고 싶다면 tuple 헤더 : #include <tuple>
tuple 값 읽을 때 : get<tuple에서 읽어올 값 인덱스>(tuple)

#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    vector<pair<int, int>> v;
    int n;
    int x, y;
    //cin >> n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        
        //cin >> x >> y;
        scanf("%d %d", &x, &y);
        v.push_back(make_pair(y, x));
    }

    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        //cout << v[i].second << " " << v[i].first << endl;
        printf("%d %d\n", v[i].second, v[i].first);
    }
    return 0;
}

0개의 댓글