blob: 977764503c2ff230bd332215fa2f2fd6ca372ffb (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char buf[1024];
char * readline() {
int i = 0;
int c;
while (1) {
c = fgetc(stdin);
if (c == EOF) {
if (i == 0) {
return NULL;
}
goto end;
}
if (c == '\n') {
goto end;
}
buf[i] = c;
i++;
}
end:
buf[i] = '\0';
return strdup(buf);
}
int main() {
int dial = 50;
char *line;
int count = 0;
while ((line = readline()) != NULL) {
int negative = 0;
if (line[0] == 'L') negative = 1;
char *end;
long val = strtol(line+1, &end, 10);
if (negative) val = -val;
if (end == line+1) continue;
dial = (dial + val) % 100;
if (dial < 0) dial += 100;
if (dial == 0) count++;
}
printf("%d\n", count);
return 0;
}
|