2
1
Fork 0
aoc2021/02/solution_1.c
Mia Herkt d6bf929fc8
Day 2: Slightly simplify C solutions
Not sure why I did it that way. Maybe because I was originally
going to use strtol or something?
2021-12-02 17:21:50 +01:00

27 lines
516 B
C

#include <stdio.h>
#include <string.h>
int main(void) {
FILE *fp = fopen("input.txt", "r");
char buf[16] = {0};
unsigned n, h = 0, v = 0;
while (fgets(buf, 16, fp) != NULL) {
sscanf(buf, "%*s %u", &n);
switch (buf[0]) {
case 'd':
v += n;
break;
case 'u':
v -= n;
break;
case 'f':
h += n;
break;
}
}
printf("Answer: %u\n", h * v);
}