This repository was archived by the owner on Feb 18, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.c
More file actions
55 lines (43 loc) · 1.29 KB
/
solution.c
File metadata and controls
55 lines (43 loc) · 1.29 KB
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
50
51
52
53
54
55
/* 考试排名 for problem 243 on XDOJ by LyCecilion - Pure C Version */
#include <stdio.h>
#include <stdlib.h>
enum
{
MAX_STUDENTS = 100,
NAME_LEN = 21 /* 20 chars + '\0' */
};
typedef struct
{
char name[NAME_LEN];
int score_1, score_2, score_3, score_4, score_5, additional;
int sum;
} student;
int cmp(const void *a, const void *b)
{
const student *sa = (const student *)a;
const student *sb = (const student *)b;
if (sa->sum > sb->sum)
return -1;
if (sa->sum < sb->sum)
return 1;
return (sa->additional < sb->additional) - (sa->additional > sb->additional);
}
int main(void)
{
int n;
if (scanf("%d", &n) != 1 || n <= 0 || n >= MAX_STUDENTS)
return 0;
student stu[MAX_STUDENTS];
for (int i = 0; i < n; ++i)
{
if (scanf("%20s %d %d %d %d %d %d", stu[i].name, &stu[i].score_1, &stu[i].score_2, &stu[i].score_3,
&stu[i].score_4, &stu[i].score_5, &stu[i].additional) != 7)
return 0;
stu[i].sum =
stu[i].score_1 + stu[i].score_2 + stu[i].score_3 + stu[i].score_4 + stu[i].score_5 + stu[i].additional;
}
qsort(stu, n, sizeof(stu[0]), cmp);
for (int i = 0; i < n; ++i)
printf("%s %d %d\n", stu[i].name, stu[i].sum, stu[i].additional);
return 0;
}