[C언어] 백준 11651 : 좌표 정렬하기 2

직전 좌표 정렬하기 1에서 compare에 x와 y값만 바꾸어주었다. 끗.
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
    int x;
    int y;
} Point;
int compare(const void *a, const void *b)
{
    Point A = *(Point *)a;
    Point B = *(Point *)b;
    if (A.y > B.y)
    {
        return 1;
    }
    else if (A.y == B.y)
    {
        if (A.x > B.x)
        {
            return 1;
        }
        else
        {
            return -1;
        }
    }
    return -1;
}
int main()
{
    int test;
    scanf("%d", &test);
    Point *arr;
    arr = (Point *)malloc(sizeof(Point) * test);
    for (int i = 0; i < test; i++)
    {
        scanf("%d %d", &arr[i].x, &arr[i].y);
    }
    qsort(arr, test, sizeof(Point), compare);
    for (int i = 0; i < test; i++)
    {
        printf("%d %d\n", arr[i].x, arr[i].y);
    }
    free(arr);
    return 0;
}Author And Source
이 문제에 관하여([C언어] 백준 11651 : 좌표 정렬하기 2), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@kimmainsain/C언어-백준-11651-좌표-정렬하기-2저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)