summaryrefslogtreecommitdiff
path: root/2022/day01/main.c
diff options
context:
space:
mode:
Diffstat (limited to '2022/day01/main.c')
-rw-r--r--2022/day01/main.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/2022/day01/main.c b/2022/day01/main.c
new file mode 100644
index 0000000..a5e21e6
--- /dev/null
+++ b/2022/day01/main.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+
+ int calsum;
+ int maxcalsum = 0;
+ int elfnum = 1;
+ int maxelfnum;
+
+ char *line = NULL;
+ size_t len = 0;
+
+ // beginning new elf
+ while (getline(&line, &len, stdin) >= 0)
+ {
+ if ( line[0] == '\n')
+ {
+ elfnum++;
+ calsum = 0;
+ continue;
+ }
+ calsum += atoi(line);
+ printf("Elf %d hat %d Kalorien\n", elfnum, calsum);
+ if ( maxcalsum < calsum)
+ {
+ maxcalsum = calsum;
+ maxelfnum = elfnum;
+ }
+ }
+
+ printf("Elf %d hat die Maximalen %d Kalorien\n", maxelfnum, maxcalsum);
+}