#include <stdio.h>

typedef struct {
    char name[20];
    int gold;
    int silver;
    int bronze;
} Country;

void sort_countries(Country arr[], int size) {
    Country temp;

    for (int i = 0; i < size - 1; i++) {
        for (int j = 0; j < size - 1; j++) {

            if (arr[j].gold < arr[j + 1].gold) {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
            else if (arr[j].gold == arr[j + 1].gold && arr[j].silver < arr[j + 1].silver) {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
            else if (arr[j].gold == arr[j + 1].gold && arr[j].silver == arr[j + 1].silver && arr[j].bronze < arr[j + 1].bronze) {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
                }
        }
    }
}

int main() {
    Country list[4] = {
        {"Korea", 5, 8, 3},
        {"USA", 10, 5, 12},
        {"China", 10, 7, 5},
        {"Japan", 5, 4, 8}
    };

    int size = 4;

    sort_countries(list, size);

    printf("--- 올림픽 순위 ---\n");
    for (int i = 0; i < size; i++) {
        printf("%d. %s (G:%d, S:%d, B:%d)\n",
               i + 1,
               list[i].name,
               list[i].gold,
               list[i].silver,
               list[i].bronze);
    }
}

Embed on website

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