BOJ 11650 좌표 정렬하기

1 개요[ | ]

BOJ 11650 좌표 정렬하기


2 C++[ | ]

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

struct point {
   int x;
   int y;
};
point p[100000];

bool comp(point p1, point p2) { return p1.x == p2.x ? p1.y < p2.y : p1.x < p2.x; }

int main() {
    int N;
    cin >> N;
    for(int i=0; i<N; i++) {
        cin >> p[i].x >> p[i].y;
    }
    sort(p, p+N, &comp);
    for(int i=0; i<N; i++) {
        cout << p[i].x << ' ' << p[i].y << '\n';
    }
}
#include <iostream>
#include <algorithm>
using namespace std;

# define x first
# define y second
pair<int, int> a[100000];

int main() {
    int N;
    cin >> N;
    for(int i=0; i<N; i++) {
        cin >> a[i].x >> a[i].y;
    }
    sort(a, a+N);
    for(int i=0; i<N; i++) {
        cout << a[i].x << ' ' << a[i].y << '\n';
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}