#include <stdio.h>
#include <stdlib.h>

typedef struct Point
{
int x;
int y;
} Point;

int compare(void const *a, void const *b) {
    const Point *A = (const Point*)a;
    const Point *B = (const Point*)b;
    if(A->y==B->y) {
        return A->x - B->x;
    } else return A->y - B->y;
}

Point arr[100001];

int main() {
    int n;
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d %d",&arr[i].x, &arr[i].y);
    }
    qsort(arr,n,sizeof(Point),compare);
    for (int i=0;i<n; i++) {
        printf("%d %d\n",arr[i].x, arr[i].y);
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: