-
Notifications
You must be signed in to change notification settings - Fork 5
/
1015-DeCaiLun.c
113 lines (110 loc) · 1.52 KB
/
1015-DeCaiLun.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include<stdio.h>
#include<stdlib.h>
int l,m;
#define SAME 0
#define A 1
#define B -1
#define H -1
#define L 1
typedef struct examinee
{
int id;
int de;
int cai;
int total;
} EXAM;
int section(EXAM *a,EXAM *b)
{
if(a->de>=m&&a->cai>=m)
{
if(b->de>=m&&b->cai>=m)
return SAME;
else
return A;
}
else if(a->de>=m&&a->cai<m)
{
if(b->de>=m&&b->cai>=m)
return B;
else if (b->de>=m&&b->cai<m)
return SAME;
else
return A;
}
else if(a->de>=a->cai&&a->de<m&&a->cai<m)
{
if(b->de>=m)
return B;
else if (b->de>=b->cai&&b->de<m&&b->cai<m)
return SAME;
else
return A;
}
else
{
if(b->de<b->cai&&b->de<m)
return SAME;
else
return B;
}
}
int compare(const void *pa,const void *pb)
{
EXAM *a,*b;
a=(EXAM *)pa;
b=(EXAM *)pb;
switch(section(a,b))
{
case SAME:
if(a->total>b->total)
{
return H;
}
else if(a->total==b->total)
{
if(a->de>b->de)
{
return H;
}
else if(a->de==b->de)
{
if(a->id>b->id)
return L;
else
return H;
}
else
return L;
}
else
return L;
case A:
return H;
case B:
return L;
}
}
int main()
{
int i,n;
EXAM *list;
scanf("%d%d%d",&n,&l,&m);
list=(EXAM *)malloc(sizeof(EXAM)*n);
for(i=0;i<n;i++)
{
scanf("%d%d%d",&list[i].id,&list[i].de,&list[i].cai);
list[i].total=list[i].de+list[i].cai;
if(list[i].de<l||list[i].cai<l)
{
i--;
n--;
}
}
qsort(list,n,sizeof(EXAM),compare);
printf("%d\n",n);
for(i=0;i<n;i++)
{
printf("%d %d %d\n",list[i].id,list[i].de,list[i].cai);
}
free(list);
}