-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_Lab08_2.c
49 lines (35 loc) · 1.04 KB
/
1_Lab08_2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#10825
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char name[11];
int korean;
int english;
int math;
} Student;
int compare(const void *a, const void *b) {
Student *studentA = (Student *)a;
Student *studentB = (Student *)b;
if (studentA->korean != studentB->korean)
return studentB->korean - studentA->korean;
if (studentA->english != studentB->english)
return studentA->english - studentB->english;
if (studentA->math != studentB->math)
return studentB->math - studentA->math;
return strcmp(studentA->name, studentB->name);
}
int main() {
int N;
scanf("%d", &N);
Student *students = (Student *)malloc(N * sizeof(Student));
for (int i = 0; i < N; i++) {
scanf("%s %d %d %d", students[i].name, &students[i].korean, &students[i].english, &students[i].math);
}
qsort(students, N, sizeof(Student), compare);
for (int i = 0; i < N; i++) {
printf("%s\n", students[i].name);
}
free(students);
return 0;
}