먼저 x좌표를 비교하고 x좌표가 같으면 y좌표를 비교하여 정렬해서 출력하면 된다.

 

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

int main(){
  int n, i;
  cin >> n;

  vector<pair <int,int>> a(n); // 쌍 벡터 
  for(i =0; i<n; i++) {
    cin >> a[i].first >> a[i].second ;
  }

  sort(a.begin(), a.end());  
  
  for (int i = 0; i < n; i++)
    cout << a[i].first << " " << a[i].second <<"\n";

}

 

[풀이법]

#include <algorithm>  -> sort() 사용

#include <utility>    ->  pair<> 사용 

#include <vector>   -> vector<> 사용

 

 

블로그 이미지

hjc_

୧( “̮ )୨

,