백준 3986 python 백준4

인지용·2026년 1월 14일

알고리즘

목록 보기
50/50
post-thumbnail
import sys

def input():
    return sys.stdin.readline().strip()


n = int(input())
size = 0

for i in range(n):
    stack = []
    arr = list(input())
    
    for k in arr:
        
        if stack and stack[-1] == k:
            stack.pop()
        else:
            stack.append(k)

    if not stack:
        size += 1

print(size)

각 문자열이 겹치지 않고 전부 소거될 수 있는지 확인하면 된다.

아래와 같은 느낌이다.

profile
한-줄

0개의 댓글