티스토리 뷰
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<list>
#include<stdlib.h>
#include<cstring>
#include<utility>
using namespace std;
bool cmp(const pair<int, int>& x, const pair<int, int>& y) //const와 &를 꼭 붙힌다
{
if (x.first < y.first)
return true;
else if (x.first == y.first)
return x.second < y.second;
else
return false;
}
int main()
{
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
vector<pair <int, int>> V(N); //각 행마다 2쌍을 가진 크기가 N인 벡터 초기화 기억잘해
for (int i = 0;i < N;i++)
cin >> V[i].first >> V[i].second;
sort(V.begin(), V.end(), cmp);
for (int i = 0;i < N;i++)
cout << V[i].first << " " << V[i].second << '\n';
}
2차원 벡터의 초기화 및 pair를 사용한 벡터의 초기화를 알아야한다.
sort 비교 인자에는 const와 & 붙히기!
'Algorithm' 카테고리의 다른 글
goodseq (백트래킹) (0) | 2021.01.30 |
---|---|
목수의 미로 탈출 (BFS) (0) | 2021.01.30 |
BOJ (백준) - 10867 (중복 빼고 정렬하기) (0) | 2020.08.20 |
BOJ (백준) - 10816 (숫자 카드 2) (0) | 2020.08.20 |
BOJ(백준) - 10866 (덱) (0) | 2020.08.16 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Kotlin
- CustomListView
- spring
- 스프링
- setOnKeyListener
- Java
- ADAPTER
- 톰캣
- 자동로그인
- DataBinding
- Android
- Eclipse
- 이클립스
- ViewModel
- Framework
- livedata
- 자바
- 로그인
- kotiln
- 스택제거
- POJO
- MutableLiveData
- SharedPreferences
- listview
- AOP
- tomcat
- ViewModelFactory
- 제어의 역행
- 안드로이드
- Enterkey
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함