T = int(input())
for test_case in range(1, T + 1):
sen = list(input())
stack = []
for i in sen :
if not stack :
stack.append(i)
continue
if stack[-1] == i:
stack.pop()
else :
stack.append(i)
print('#{} {}'.format(test_case, len(stack)))
'알고리즘' 카테고리의 다른 글
[SWEA] 괄호 검사 (Python) (0) | 2020.10.21 |
---|---|
[SWEA] 그래프 경로 (Python) (0) | 2020.10.21 |
[백준] 2606. 바이러스 (Python) (0) | 2020.10.21 |
[백준] 2667. 단지번호붙이기 (DFS/Python) (0) | 2020.10.21 |
[SWEA] 5097. 회전 (Python) (0) | 2020.10.21 |