C빈칸 채우기보통 · 20점#구조체#정렬#배열

80. 구조체 배열을 점수와 이름 순으로 정렬

다음은 학생을 점수 내림차순으로, 점수가 같으면 이름의 사전 순으로 정렬하는 C 프로그램이다. 실행 결과가 차례로 `1 joon 95`, `2 ara 82`, `3 mina 82`, `4 hyun 70`이 되도록 빈칸 ①에 들어갈 string.h의 함수 이름을 쓰시오.

1#include <stdio.h>
2#include <string.h>
3
4struct Student {
5 char name[8];
6 int score;
7};
8
9int main() {
10 struct Student s[4] = {{"mina", 82}, {"joon", 95}, {"ara", 82}, {"hyun", 70}};
11 for (int i = 0; i < 3; i++) {
12 int m = i;
13 for (int j = i + 1; j < 4; j++) {
14 if (s[j].score > s[m].score || (s[j].score == s[m].score && ( ① )(s[j].name, s[m].name) < 0)) {
15 m = j;
16 }
17 }
18 struct Student t = s[i];
19 s[i] = s[m];
20 s[m] = t;
21 }
22 for (int i = 0; i < 4; i++) {
23 printf("%d %s %d\n", i + 1, s[i].name, s[i].score);
24 }
25 return 0;
26}

해설을 먼저 보면 이후 정답 시 점수가 50%만 반영됩니다.