[BOJ] 9012. ๊ดํธ(python)
๐๋ฌธ์
๐ช์์ด๋์ด
- โ( )โ ์ง ๋ง์ถ๊ธฐ
- โ(โ๋ฉด ์คํ์ ๋ฃ๊ธฐ
- โ)โ๋ฉด ์คํ[-1] โ(โ ๋นผ๊ธฐ
stack์ด ๋น์ด์๋ ๋ฐ โ)โ๋ค์ด์ค๋ฉด VPS์๋ - ๋ฌธ์์ด์ด ๋๋ฌ๋๋ฐ ๋น stack์ด ์๋๋ฉด VPS์๋
๐ฅ์ฝ๋
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
T = int(input())
for _ in range(T):
PS = input()
left_stack=[]
answer='NO'
for ch in PS:
if ch=='(':left_stack.append(ch)
else:
if not left_stack: break
left_stack.pop()
else:
if not left_stack: answer='YES'
print(answer)
This post is licensed under CC BY 4.0 by the author.
Comments powered by Disqus.