-
Notifications
You must be signed in to change notification settings - Fork 13
/
the-dart-101.c
45 lines (38 loc) · 1.61 KB
/
the-dart-101.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
main() {
int N; scanf("%d", &N); fgetc(stdin);
char pl [N][1025], turn [N][1025];
int sc [N], w_turn[N];
for (int i = 0; i < N; i++) { fgets(pl[i] , 1025, stdin); }
for (int i = 0; i < N; i++) { fgets(turn[i], 1025, stdin); }
for (int i = 0; i < N; i++) {
fprintf(stderr, "%s%s\n", pl[i], turn[i]);
w_turn[i] = 1e9;
int t_fails = 0, c_fails = 0, c_turn = 0, cmpt = 0, ts = 0;
char *p = strtok(turn[i], " ");
while(p != NULL) {
cmpt++;
int tmp = atoi(p);
if ( *p == 'X' ) {
sc[i] -= 20;
if (++t_fails == 3) { sc[i] = 0; }
else if (++c_fails == 2) { sc[i] -= 10; }
}
else {
c_fails = 0;
if ( *(p+1) == '*' ) { tmp = (*p-'0')*atoi(p+2); }
if ( sc[i] + tmp > 101 ) { t_fails = 0; c_fails = 0; c_turn++; cmpt = 0; sc[i] = ts; }
else { sc[i] += tmp; }
}
if ( sc[i] == 101 ) { w_turn[i] = c_turn; }
if ( cmpt > 0 && cmpt%3 == 0 ) { t_fails = 0; c_fails = 0; c_turn++; cmpt = 0; ts = sc[i]; }
p = strtok(NULL, " ");
}
}
int m_turn = 1e9, m_index = 0;
for (int i = 0; i < N; i++)
if ( w_turn[i] < m_turn ) { m_index = i; m_turn = w_turn[i]; }
printf("%s", pl[m_index]);
}