https://www.acmicpc.net/problem/4889
def count_operations_to_stable(s):
stack = []
operations = 0
for char in s:
if char == '{':
stack.append(char)
else: # char == '}'
if stack:
stack.pop()
else:
operations += 1
stack.append('{')
operations += len(stack) // 2
return operations
test_case_number = 1
while True:
input_string = input().strip()
if input_string.startswith('-'):
break
result = count_operations_to_stable(input_string)
print(f"{test_case_number}. {result}")
test_case_number += 1
'알고리즘 문제풀이' 카테고리의 다른 글
Heat Wave[백준 5996] (0) | 2024.09.11 |
---|---|
Road to Savings[백준 27617] (0) | 2024.09.10 |
치킨 TOP N [백준 11582] (0) | 2024.07.21 |
줄 세우기 [백준 11536] (0) | 2024.07.19 |
순회강연 [백준 2109] (0) | 2024.07.18 |