1 #include <stdio.h>
2 #include <stdlib.h>
3 #define MAXSIZE 100000
4 typedef struct
5 {
6 int ID; //考号
7 int Moral_Mark; //德分
8 int Talent_Mark; //才分
9 } STData;
10
11 STData MTH_ST[MAXSIZE], MH_ST[MAXSIZE], MtTL_ST[MAXSIZE], MTL_ST[MAXSIZE];
12 //比较函数
13 int cmp(const void *a, const void *b);
14
15 int main(void)
16 {
17 int Quantity, H_Level, L_Level;
18 int count = 0, MTH_count = 0, MH_count = 0, MtTL_count = 0, MTL_count = 0;
19 scanf("%d%d%d", &Quantity, &L_Level, &H_Level);
20
21 for (int i = 0; i < Quantity; i++)
22 {
23 STData temp;
24 scanf("%d %d %d", &temp.ID, &temp.Moral_Mark, &temp.Talent_Mark);
25 if (temp.Moral_Mark >= L_Level && temp.Talent_Mark >= L_Level) //德分和才分高于最低线(前提)
26 {
27 count++;
28 if (temp.Moral_Mark >= H_Level && temp.Talent_Mark >= H_Level) //德分和才分高于优秀线
29 {
30 MTH_ST[MTH_count++] = temp;
31 continue;
32 }
33 if (temp.Moral_Mark >= H_Level && temp.Talent_Mark < H_Level) //德分高于优秀线
34 {
35 MH_ST[MH_count++] = temp;
36 continue;
37 }
38 if (temp.Moral_Mark < H_Level && temp.Talent_Mark < H_Level && temp.Talent_Mark <= temp.Moral_Mark) //德分高于才分,且德分才分低于优秀线
39 {
40 MtTL_ST[MtTL_count++] = temp;
41 continue;
42 }
43 MTL_ST[MTL_count++] = temp; //余下的
44 }
45 }
46
47 //排序
48 qsort(MTH_ST, MTH_count, sizeof(STData), cmp);
49 qsort(MH_ST, MH_count, sizeof(STData), cmp);
50 qsort(MtTL_ST, MtTL_count, sizeof(STData), cmp);
51 qsort(MTL_ST, MTL_count, sizeof(STData), cmp);
52
53 printf("%d\n", count);
54 for (int i = 0; i < MTH_count; i++)
55 {
56 printf("%d %d %d\n", MTH_ST[i].ID, MTH_ST[i].Moral_Mark, MTH_ST[i].Talent_Mark);
57 }
58 for (int i = 0; i < MH_count; i++)
59 {
60 printf("%d %d %d\n", MH_ST[i].ID, MH_ST[i].Moral_Mark, MH_ST[i].Talent_Mark);
61 }
62 for (int i = 0; i < MtTL_count; i++)
63 {
64 printf("%d %d %d\n", MtTL_ST[i].ID, MtTL_ST[i].Moral_Mark, MtTL_ST[i].Talent_Mark);
65 }
66 for (int i = 0; i < MTL_count; i++)
67 {
68 printf("%d %d %d\n", MTL_ST[i].ID, MTL_ST[i].Moral_Mark, MTL_ST[i].Talent_Mark);
69 }
70 return 0;
71 }
72
73 //比较函数
74 int cmp(const void *a, const void *b)
75 {
76 STData *Ptra = (STData *)a;
77 STData *Ptrb = (STData *)b;
78 int Total_Marka = Ptra->Moral_Mark + Ptra->Talent_Mark;
79 int Total_Markb = Ptrb->Moral_Mark + Ptrb->Talent_Mark;
80
81 if (Total_Marka != Total_Markb)
82 {
83 return Total_Markb - Total_Marka;
84 }
85 else
86 {
87 if (Ptra->Moral_Mark != Ptrb->Moral_Mark)
88 {
89 return Ptrb->Moral_Mark - Ptra->Moral_Mark;
90 }
91 else
92 {
93 return Ptra->ID - Ptrb->ID;
94 }
95 }
96 }