summaryrefslogtreecommitdiffstats
path: root/inf/aoc/1.c
diff options
context:
space:
mode:
Diffstat (limited to 'inf/aoc/1.c')
-rw-r--r--inf/aoc/1.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/inf/aoc/1.c b/inf/aoc/1.c
new file mode 100644
index 0000000..2bb65b9
--- /dev/null
+++ b/inf/aoc/1.c
@@ -0,0 +1,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);
+}