summaryrefslogtreecommitdiffstats
path: root/inf/aoc/1.c
blob: 2bb65b9a4bcdffbee9bbe690f8e917ef088eff1b (plain) (blame)
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 <stdio.h>
#include <stdlib.h>
int main (void) {
	char b[64];
	unsigned m = 0;
	unsigned n = 0;
	unsigned o = 0;
	unsigned s = 0;
	unsigned t;
	while (!ferror(stdin) && !feof(stdin)) {
		if (m < o) {
			t = o;
			o = m;
			m = t;
		}
		if (n < o) {
			t = o;
			o = n;
			n = t;
		}
		fgets(b, 64, stdin);
		if (b[0] == '\n') {
			if (s > m) {
				o = n;
				n = m;
				m = s;
				goto c;
			}
			if (s > n) {
				o = n;
				n = s;
				goto c;
			}
			if (s > o) {
				o = s;
				goto c;
			}
			c:
			s = 0;
		} else {
			s += atoi(b);
		}
	}
	printf("%u %u %u sum %u\n", m, n, o, m+n+o);
}