diff options
Diffstat (limited to 'day1.c')
-rw-r--r-- | day1.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -1,8 +1,9 @@ #include <stdio.h> int main() { - int ch, floor = 0; + int ch, floor = 0, pos = 0, first_basement = 1; while ((ch = getchar()) != EOF) { + pos += 1; switch(ch) { case '(': floor += 1; @@ -10,7 +11,11 @@ int main() { case ')': floor -= 1; } + if (floor == -1 && first_basement) { + printf("In the basement at position: %d\n", pos); + first_basement = 0; + } } - printf("%d\n", floor); + printf("Final floor: %d\n", floor); return 0; } |