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
반응형

+ Recent posts