diff --git a/02/solution_1.c b/02/solution_1.c new file mode 100644 index 0000000..f50634c --- /dev/null +++ b/02/solution_1.c @@ -0,0 +1,31 @@ +#include +#include +#include + +int main(void) { + FILE *fp = fopen("input.txt", "r"); + char buf[16] = {0}, *np; + unsigned n, h = 0, v = 0; + + while (fgets(buf, 16, fp) != NULL) { + np = strchr(buf, ' '); + assert(np != NULL); + np++; + + sscanf(np, "%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); +}