코딩 이야기/백준 풀이
백준 11650번: 좌표 정렬하기 C++코드(정렬)
우기 woogi
2021. 7. 31. 12:16
반응형
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
int main(){
int n;
int temp, temp2;
vector <pair<int, int> > arr;
scanf("%d", &n);
for(int i=0; i<n; i++){
scanf("%d %d", &temp, &temp2);
pair<int,int> temp3 = make_pair(temp,temp2);
arr.push_back(temp3);
}
sort(arr.begin(), arr.end());
for(int i=0; i<n; i++){
printf("%d %d \n", arr[i].first, arr[i].second);
}
}
설명
단순한 정렬 문제이다. 그나마 주의해야할 점은 정렬함수는 pair를 정렬할 때 앞에 있는 값을 정렬하고 뒤에 있는 값을 정렬하기 때문에, 당연히 <x,y>순으로 벡터에 넣어주어야한다.
문제점
없다.
반응형