Coding Test - cpp/Sort
[백준 11650: 좌표 정렬하기] - C++
에드윈H
2021. 3. 4. 17:17
11650번: 좌표 정렬하기
첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다.
www.acmicpc.net
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
struct Location
{
public:
Location(int x, int y)
: mX(x)
, mY(y)
{}
int mX;
int mY;
bool operator<(const Location& ref) const
{
if (ref.mX > mX)
{
return true;
}
if (ref.mX == mX)
{
if (ref.mY > mY)
return true;
else
return false;
}
else
return false;
}
};
int main(void)
{
vector<Location> list;
int n;
int x;
int y;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
list.push_back(Location(x, y));
}
sort(list.begin(), list.end());
for (int i = 0; i < n; i++)
{
cout << list[i].mX << " " << list[i].mY << '\n';
}
return 0;
}