advent-of-code/2022/day01/main.c
2022-12-17 01:16:18 +01:00

35 lines
665 B
C

#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);
}