123isi   2년 전

/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include 

typedef struct {
    int score;
    char name[100];
    int sunseo;
} student;

int main(void)
{
    student people[1000];
    int n;
    int max;
    student swap;
    
    scanf("%d ", &n);
    for(int i = 0; i < n; ++i) {
        scanf("%d %s", &people[i].score, people[i].name);
        people[i].sunseo = i;
    }
    for(int i = 0; i < n; ++i) {
        max = i;
        for(int j = i + 1; j < n; ++j) {
            if (people[j].score < people[max].score) max = j;
            else if (people[j].score == people[max].score && people[j].sunseo < people[max].sunseo) max = j;
        }
        
        swap = people[i];
        people[i] = people[max];
        people[max] = swap;
    }
    
    for(int i = 0; i < n; ++i)
        printf("%d %s\n",people[i].score, people[i].name);
    return 0;
}

123isi   2년 전

내공 300

djm03178   2년 전

첫째 줄에 온라인 저지 회원의 수 N이 주어진다. (1 ≤ N ≤ 100,000)

댓글을 작성하려면 로그인해야 합니다.