입출력
풀이
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int cnt;
int x, y;
vector<pair<int, int>> xys;
cin >> cnt;
for (int i = 0; i < cnt; i++)
{
cin >> x >> y;
xys.push_back({ x, y }); //xys.push_back(make_pair(x, y));
}
sort(xys.begin(), xys.end());
for (int i = 0; i < cnt; i++)
{
cout << xys[i].first << " "<< xys[i].second << "\n";
}
}
sort()함수는 자동으로 첫번째를 비교하고 같은 값일 경우 두번째를 비교하여 정렬한다
2차원 vector를 이용하여 x,y값을 저장해준다
'> 코딩테스트' 카테고리의 다른 글
[백준] 10815 숫자 카드 (C++) (1) | 2023.06.11 |
---|---|
[백준] 10814 나이순 정렬 (C++) (0) | 2023.06.07 |
[백준] 1181 단어 정렬 (C++) (0) | 2023.06.06 |
[백준] 11651 좌표 정렬하기2 (C++) (0) | 2023.06.06 |
[백준] 10989 수 정렬하기 (C++) (0) | 2023.06.04 |