songining
article thumbnail

์ฒ˜์Œ์—๋Š” ๋ฌธ์ œ๊ฐ€ ์ดํ•ด๊ฐ€ ์•ˆ๊ฐ”๋Š”๋ฐ ๊ทธ๋ƒฅ A์™€ A๋ฅผ ์ง์ง“๊ณ  B์™€ B๋ฅผ ์ง์ง€์—ˆ์„ ๋•Œ ๊ฒน์น˜๋Š” ์„ ์ด ์—†๊ณ  ๋‚จ๋Š” ๋ฌธ์ž๊ฐ€ ์—†์œผ๋ฉด ์ข‹์€ ๋ฌธ์ž๋กœ ์„ธ์–ด์ฃผ๋Š” ๊ฒƒ์ด์—ˆ๋‹ค. 

์ด ๋ฌธ์ œ๋ฅผ ํ‘ธ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ 

1. ์Šคํƒ์— ๊ฐ™์€ ๋ฌธ์ž๊ฐ€ ๋“ค์–ด์˜ค๋ฉด pop

2. ์Šคํƒ์— ๋‹ค๋ฅธ ๋ฌธ์ž๊ฐ€ ๋“ค์–ด์˜ค๋ฉด push ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. 

 

ํŒŒ์ด์ฌ์œผ๋กœ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์งœ๊ธฐ ์‹œ์ž‘ํ•œ์ง€ ์–ผ๋งˆ ๋˜์ง€ ์•Š์•„ ๋ฆฌ์ŠคํŠธ๊ฐ€ ๋น„์–ด์žˆ์„ ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ์กฐ๊ฑด๋ฌธ์„ ๋งŒ๋“ค๋•Œ ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด len(stack)์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ํ›จ์”ฌ ๋‚˜์€ ์ฝ”๋“œ๋ผ๋Š” ๊ฒƒ๋„ ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค. 

 

if not stack:

 

๊ทธ๋ฆฌ๊ณ  ๋ฆฌ์ŠคํŠธ์˜ ๋งˆ์ง€๋ง‰ ์›์†Œ์— ์ ‘๊ทผํ•  ๋•Œ stack[-1]์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋˜์—ˆ๋‹ค.

 

def main():
    n = int(input())
    word_list = []
    stack=[]
    count = 0

    for _ in range(n):
        word_list.append(input())

    for word in word_list:
        for i in range(0,len(word)):
            if not stack:
                stack.append(word[i])
            else:
                if stack[-1]==word[i]:
                    stack.pop()
                else:
                    stack.append(word[i])
        if not stack:
            count+=1
        stack=[]
    print(count)


if __name__ == '__main__':
    main()