SDJ( 수돈재 아님 ㅎ )

[C++] 11651 - 좌표 정렬하기 2 본문

알고리즘/Backjoon

[C++] 11651 - 좌표 정렬하기 2

ShinDongJun 2019. 12. 24. 12:28

문제 링크 : https://www.acmicpc.net/problem/11651

 

11651번: 좌표 정렬하기 2

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

www.acmicpc.net

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
#include<algorithm>
#define endl '\n'
 
using namespace std;
 
typedef struct point
{
    int x, y;    
}P;
 
bool cmp(const P &p1, const P &p2){
    if(p1.x < p2.x){
        return true;
    }
    else if(p1.x == p2.x){
        return p1.y < p2.y;
    }
    else{
        return false;
    }
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    P array[100005];
 
    int N;
    cin >> N;
 
    for(int i = 0; i < N; ++i)
    {
        cin >> array[i].y >> array[i].x;
    }
 
    sort(array, array+N, cmp);
 
 
    for(int i = 0; i < N; ++i)
        cout << array[i].y << ' ' << array[i].x << endl;
 
 
    return 0;
}

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

[Python3] 13413 - 오셀로 재배치  (0) 2020.01.03
[Python3] 13410 - 거꾸로 구구단  (0) 2020.01.03
[C++] 1145 - 적어도 대부분의 배수  (0) 2019.12.23
[C++] 12865 - 평범한 배낭  (0) 2019.12.23
[C++] 2565 - 전깃줄  (0) 2019.12.23
Comments