#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool compare(pair<int,int>a,pair<int,int>b){
if(a.second==b.second){
return a.first<b.first;
}
else return a.second<b.second;
}
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
vector <pair<int, int>>v;
cin >> T;
for(int i=0; i<T; i++){
int a,b = 0;
cin >> a >> b;
v.push_back(pair<int,int>(a,b));}
sort(v.begin(),v.end(),compare);
for(int i=0; i<T; i++){
cout << v[i].first << " " << v[i].second << "\n";}
return 0;
}
Sort함수의 pair기능을 알아내면 그다지 어렵지 않은 문제 였으나,
Sort 함수에 대해 더 많이 탐구 하고 싶다.
그냥 Sort함수만 있으면 잘 풀리는구나~ 에서 끝나는 1차원 적인 생각이 아니라,
Sort함수의 원리를 알고싶다.
Sort함수와 기본 3개 소트(삽입, 선택, 버블), 퀵소트, 머지소트, 힙소트와의 차이를 알고싶다.
주말에 시간을 내서 더 열심히 탐구해보자.
'🖥️ CS > Baekjoon Algorithms' 카테고리의 다른 글
#10814 나이순정렬 (c++) (0) | 2020.03.13 |
---|---|
#1181번 단어정렬 (c++) (0) | 2020.03.12 |
#1427번 소트인사이드 (c++) (0) | 2020.03.08 |
#2108번 통계학 (c++) (0) | 2020.03.08 |
#2550번 수 정렬하기 (c++) (0) | 2020.03.03 |