summaryrefslogtreecommitdiff
path: root/2022/day01/main.c
blob: a5e21e6ccd8831a58bc18fcef4396cd7ea26b263 (plain)
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
#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);
}