Skip to content

Commit

Permalink
2024-05-09 원숭이 매달기
Browse files Browse the repository at this point in the history
  • Loading branch information
suhyun113 committed Jul 1, 2024
1 parent 18ce7d3 commit c298587
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions suhyun113/트리/7-suhyun113.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 2716 : 원숭이 매달기

N = int(input()) # 테스트 케이스의 개수
results = []

for _ in range(N):
s = input().strip()
len_s = len(s)

depth = 0
max_depth = 0

for i in range(len_s):
if (s[i] == '['):
depth += 1
if (depth > max_depth):
max_depth = depth
elif (s[i] == ']'):
depth -= 1

result = 1 #나무 꼭대기 도달위해 최소 한 마리 원숭이 필요
for _ in range(max_depth):
result *= 2
results.append(result)

for result in results:
print(result)

0 comments on commit c298587

Please sign in to comment.