Baekjoon 11650
좌표 정렬하기


QUESTION ❔



CODE ⌨️

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

class pnt
{
public:
	int x;
	int y;
};

int N;
vector<pnt> vec;

bool cmp(pnt p1, pnt p2)
{
	if (p1.x == p2.x)
	{
		return p1.y < p2.y;
	}
	else return p1.x < p2.x;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		pnt np;

		cin >> np.x >> np.y;

		vec.push_back(np);
	}

	sort(vec.begin(), vec.end(), cmp);

	for (int i = 0; i < vec.size(); i++)
	{
		cout << vec[i].x << " " << vec[i].y << "\n";
	}

	return 0;
}



RESULT 💛



SIMPLE DISCUSSION ✏️

정렬 관련 문제였다.



SOURCE 💎

Baekjoon_Link 👈 Click here


*****
NOT A TALENT ❎ NOT GIVING UP ✅
CopyRight ⓒ 2022 DCherish All Rights Reserved.