49 lines
906 B
C
49 lines
906 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "../../lib/aoc.h"
|
|
|
|
int main() {
|
|
int current_cals = 0;
|
|
int current_elf = 0;
|
|
int max_elf = 0;
|
|
int second_max_elf = 0;
|
|
int third_max_elf = 0;
|
|
|
|
char *line;
|
|
|
|
while ((line = aoc_read_line()) != NULL) {
|
|
if (strlen(line) == 0) {
|
|
if (current_elf > max_elf) {
|
|
int z = current_elf;
|
|
current_elf = max_elf;
|
|
max_elf = z;
|
|
}
|
|
|
|
if (current_elf > second_max_elf) {
|
|
int z = current_elf;
|
|
current_elf = second_max_elf;
|
|
second_max_elf = z;
|
|
}
|
|
|
|
if (current_elf > third_max_elf) {
|
|
int z = current_elf;
|
|
current_elf = third_max_elf;
|
|
third_max_elf = z;
|
|
}
|
|
|
|
current_elf = 0;
|
|
} else {
|
|
current_cals = atoi(line);
|
|
current_elf += current_cals;
|
|
}
|
|
}
|
|
|
|
printf("Part 1: %d\n", max_elf);
|
|
printf("Part 2: %d\n", max_elf + second_max_elf + third_max_elf);
|
|
|
|
aoc_free();
|
|
return 0;
|
|
}
|