AoC2022/01_02.c

30 lines
478 B
C
Raw Normal View History

2022-12-03 01:26:39 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
char cur[20];
int cur_sum = 0;
int max = 0;
int second = 0;
int third = 0;
while (fgets(cur,20,stdin) != NULL) {
if (strlen(cur) > 1) {
cur_sum += atoi(cur);
if (cur_sum > max) {
max = cur_sum;
} else if (cur_sum > second) {
second = cur_sum;
} else if (cur_sum > third) {
third = cur_sum;
}
} else {
cur_sum = 0;
}
}
printf("%d\n", max+second+third);
}