Agorithm/백준 알고리즘
백준 알고리즘 3986번 좋은 단어(python)
kimjinho1
2021. 3. 5. 14:05
728x90
반응형
기본적인 스택 문제이다.
cnt = 0
for _ in range(int(input())):
s = input()
stack = []
for c in s:
if c == 'A':
if stack == [] or (stack != [] and stack[-1] != 'A'):
stack.append(c)
else:
stack.pop()
if c == 'B':
if stack == [] or (stack != [] and stack[-1] != 'B'):
stack.append(c)
else:
stack.pop()
if not stack:
cnt += 1
print(cnt)
728x90
반응형