정신과 시간의 방
카테고리
작성일
2024. 6. 28. 20:22
작성자
risehyun
  • 문제

 

  • 풀이
#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