diff options
Diffstat (limited to 'day1/day1.c')
-rw-r--r-- | day1/day1.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/day1/day1.c b/day1/day1.c new file mode 100644 index 0000000..dbd188d --- /dev/null +++ b/day1/day1.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +int main() { + int ch, floor = 0, pos = 0, first_basement = 1; + while ((ch = getchar()) != EOF) { + pos += 1; + switch(ch) { + case '(': + floor += 1; + break; + case ')': + floor -= 1; + } + if (floor == -1 && first_basement) { + printf("In the basement at position: %d\n", pos); + first_basement = 0; + } + } + printf("Final floor: %d\n", floor); + return 0; +} |