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;

}

dgddgd   2년 전

bubble sort보다 더 빠른 정렬 알고리즘을 사용하셔야 할 것 같습니다.

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