Coding Test - cpp/Sort
[백준 11650: 좌표 정렬하기] - C++
에드윈H
2021. 3. 4. 17:17
#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;
}