- 문제
- 풀이
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n = 0;
cin >> n;
vector<pair<int, int>> points(n);
for (int i = 0; i < n; i++)
{
cin >> points[i].second >> points[i].first;
}
sort(points.begin(), points.end());
for (int i = 0; i < n; i++)
{
cout << points[i].second << ' ' << points[i].first << '\n';
}
return 0;
}
- 메모
아래 링크의 좌표 정렬하기 1 문제와 동일한데, 정렬 기준만 다르기 때문에 입력과 출력시 y와 x의 순서만 바꿔주었다.
pair와 sort에 대한 내용은 아래 포스팅에서 언급했다.
https://risehyun.tistory.com/425
[백준/11650번/C++] 좌표 정렬하기
문제 풀이#include #include #include using namespace std;int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n = 0; cin >> n; vector> points(n); for (int i = 0; i > points[i].first >> points[i].second; } sort(points.begin
risehyun.tistory.com
'코딩테스트' 카테고리의 다른 글
[백준/1181번/C++] 단어 정렬 (0) | 2024.07.03 |
---|---|
[백준/10814번/C++] 나이순 정렬 (0) | 2024.06.30 |
[백준/11650번/C++] 좌표 정렬하기 (0) | 2024.06.26 |
[백준/2751번/C++] 수 정렬하기 2 (0) | 2024.06.25 |
[백준/9012번/C++] 괄호 (0) | 2024.06.20 |