blob: dbd188d3b68d85d628aff615595038b80f10c3c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
}
|