-
Notifications
You must be signed in to change notification settings - Fork 9
/
decode.c
64 lines (48 loc) · 939 Bytes
/
decode.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <assert.h>
const int w_sz = 3;
short w[3] = { 0, -1, 0 };
void shift(short v) {
int i;
for (i = 0; i < w_sz - 1; i++) {
w[i] = w[i + 1];
}
w[i] = v;
}
int is_max() {
if (w[1] > w[0] && w[1] > w[2])
return 1;
return 0;
}
int main() {
short val;
int n;
int run = 0;
char skip[256];
assert(sizeof(val) == 2);
n = read(0, skip, 44);
if (n != 44) {
perror("READ");
exit(EXIT_FAILURE);
}
while (1) {
n = read(0, &val, sizeof(val));
if (n == 0)
break;
if (n == -1) {
perror("read()");
exit(EXIT_FAILURE);
}
shift(val);
if (is_max()) {
printf("%d\n", run);
run = 0;
} else {
run++;
}
}
exit(EXIT_SUCCESS);
}