-
Notifications
You must be signed in to change notification settings - Fork 0
/
1080.c
117 lines (106 loc) · 2.88 KB
/
1080.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
114
115
116
117
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct student{
char name[21];
int program;
int mid;
int final;
int total;
}s[10001];
int cmpname(const void *a,const void *b)
{
struct student s1 = *(struct student*)a;
struct student s2 = *(struct student*)b;
return strcmp(s1.name, s2.name);
}
int cmptotal(const void *a,const void *b)
{
struct student s1 = *(struct student*)a;
struct student s2 = *(struct student*)b;
if(s1.total - s2.total){
return s2.total - s1.total;
}
return strcmp(s1.name, s2.name);
}
int main()
{
int p,m,n,i,j,count=0,score;
char tmp[21];
scanf("%d%d%d",&p,&m,&n);
for(i = 0; i < p; i++){
scanf("%s%d",tmp,&score);
if(score >= 200){
strcpy(s[count].name,tmp);
s[count].program = score;
s[count].mid = -1;
s[count].final = -1;
s[count].total = 0;
count++;
}
}
qsort(s,count,sizeof(s[0]),cmpname); // 二分法数列必须有序
for(i = 0; i < m; i++){
scanf("%s%d",tmp,&score);
// for(j = 0; j < count; j++){
// if(strcmp(s[j].name,tmp) == 0){
// s[j].mid = score;
// }
// }
int a = 0,b = count - 1;
while(a <= b){
int c = (a + b) / 2;
if(strcmp(s[c].name,tmp) == 0){
s[c].mid = score;
break;
}
else if(strcmp(s[c].name,tmp) < 0){
a = c + 1;
}
else{
b = c - 1;
}
}
}
for(i = 0; i < n; i++){
scanf("%s%d",tmp,&score);
// for(j = 0; j < count; j++){
// if(strcmp(s[j].name,tmp) == 0){
// s[j].final = score;
// if(s[j].final >= s[j].mid){
// s[j].total = s[j].final;
// }
// else{
// s[j].total = (s[j].mid * 0.4 + s[j].final * 0.6 + 0.5); //+0.5四舍五入
// }
// }
// }
int a = 0,b = count - 1;
while(a <= b){
int c = (a + b) / 2;
if(strcmp(s[c].name,tmp) == 0){
s[c].final = score;
if(s[c].final >= s[c].mid){
s[c].total = s[c].final;
}
else{
s[c].total = (s[c].mid * 0.4 + s[c].final * 0.6 + 0.5);
}
break;
}
else if(strcmp(s[c].name,tmp) < 0){
a = c + 1;
}
else{
b = c - 1;
}
}
}
qsort(s,count,sizeof(s[0]),cmptotal);
for(i = 0; i < count; i++){
if(s[i].total >= 60){
printf("%s %d %d %d %d\n",s[i].name, s[i].program, s[i].mid, s[i].final, s[i].total);
}
}
return 0;
}