나의 브을로오그으

[c++] 11650번 : 좌표 정렬하기 본문

알고리즘/BaekJoon

[c++] 11650번 : 좌표 정렬하기

__jhp_+ 2022. 5. 12. 14:26

https://www.acmicpc.net/problem/11650

 

11650번: 좌표 정렬하기

첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다.

www.acmicpc.net

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef struct Point {
	int x;
	int y;
	Point(int x, int y) {
		this->x = x;
		this->y = y;
	}
}POINT, *PPOINT;

int compare(POINT p1, POINT p2)
{
	return p1.x == p2.x ? p1.y < p2.y : p1.x < p2.x;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	vector<POINT> v;
	v.reserve(100000);
	
	int N = 0;
	int x, y;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> x >> y;
		POINT point(x, y);
		v.push_back(point);
	}
	sort(begin(v), end(v), compare);
	for (int i = 0; i < N; ++i)
	{
		cout << v[i].x << ' ' << v[i].y << '\n';
	}

	return 0;
}

'알고리즘 > BaekJoon' 카테고리의 다른 글

[c++] 11866번 : 요세푸스 문제 0  (0) 2022.05.12
[c++] 11651번 : 좌표 정렬하기2  (0) 2022.05.12
[c++] 11050번 : 이항 계수 1  (0) 2022.05.10
[c++] 10989번 : 수 정렬하기3  (0) 2022.05.10
[c++] 10866번 : 덱  (0) 2022.05.10