forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10698.cpp
183 lines (180 loc) · 2.69 KB
/
10698.cpp
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <bits/stdc++.h>
using namespace std;
/*
10698
Football Sort
*/
map<string, int> M;
struct ss
{
char nam[20];
char Or[20];
char avg[20];
int played;
int point;
int goaldiff;
int goal;
int aga;
};
ss F[30];
int team, game;
char xx[] = "N/A";
int Com(const void *a, const void *b)
{
ss *x = (ss *)a;
ss *y = (ss *)b;
if (x->played == 0 && y->played == 0)// op
{
return strcmp(x->nam, y->nam);// op
}
if (x->played && y->played == 0)// op
{
return y->played - x->played;// op
}
if (x->played == 0 && y->played)//op
{
return y->played - x->played;//op
}
if (x->point != y->point)
{
return y->point - x->point;
}
if (x->goaldiff != y->goaldiff)
{
return y->goaldiff - x->goaldiff;
}
if (x->goal != y->goal)
{
return y->goal - x->goal;
}
return strcmp(x->nam, y->nam);
}
void ReadCase()
{
int i, ga, gb, ia, ib;
char ta[20], tb[20];
for (i = 0; i < team; i++)
{
scanf("%s", F[i].Or);
M[F[i].Or] = i + 1;
for (ia = 0; F[i].Or[ia]; ia++)
{
F[i].nam[ia] = tolower(F[i].Or[ia]);
}
}
while (game--)
{
scanf("%s%d%s%d%s", ta, &ga, tb, &gb, tb);
ia = M[ta] - 1;
ib = M[tb] - 1;
F[ia].goal += ga;
F[ib].goal += gb;
F[ia].goaldiff += ga - gb;
F[ib].goaldiff += gb - ga;
F[ia].played++;
F[ib].played++;
F[ia].aga += gb;
F[ib].aga += ga;
if (ga > gb)
{
F[ia].point += 3;
}
else if (gb > ga)
{
F[ib].point += 3;
}
else
{
F[ia].point++;
F[ib].point++;
}
}
}
int isEqual(int n, int m)
{
if (F[n].point != F[m].point)
{
return 0;
}
if (F[n].goaldiff != F[m].goaldiff)
{
return 0;
}
if (F[n].goal != F[m].goal)
{
return 0;
}
return 1;
}
void Print()
{
int i;
char xyz[] = " ";
printf("%2d.%16s%4d%4d%4d%4d%4d%7s\n", 1, F[0].Or, F[0].point, F[0].played,
F[0].goal, F[0].aga, F[0].goaldiff, F[0].avg);
for (i = 1; i < team; i++)
{
if (isEqual(i, i - 1))
{
printf("%s", xyz);
}
else
{
printf("%2d.", i + 1);
}
printf("%16s%4d%4d%4d%4d%4d%7s\n", F[i].Or, F[i].point, F[i].played,
F[i].goal, F[i].aga, F[i].goaldiff, F[i].avg);
}
}
void Cal()
{
int i, j;
double xyz;
char tt[10];
for (i = 0; i < team; i++)
{
if (F[i].played)
{
xyz = (double)F[i].point * 100 / (double)(F[i].played * 3);
sprintf(tt, "%.2lf", xyz);
strcpy(F[i].avg, tt);
}
else
{
strcpy(F[i].avg, xx);
}
}
Print();
}
void ReSet()
{
int i;
for (i = 0; i < team; i++)
{
F[i].goaldiff = F[i].point = 0;
F[i].played = 0;
F[i].aga = 0;
F[i].goal = 0;
}
}
int main()
{
int f = 0;
while (scanf("%d%d", &team, &game) == 2)
{
if (!team && !game)
{
break;
}
ReSet();
ReadCase();
qsort(F, team, sizeof(ss), Com);
if (f++)
{
printf("\n");
M.empty();
}
Cal();
}
return 0;
}