Skip to content

Commit 4972cf6

Browse files
authored
[BOJ] 9012 괄호 (S4)
1 parent 74074fa commit 4972cf6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

김지호/7주차/260213.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
T = int(input())
2+
3+
for i in range(T):
4+
stack = []
5+
a=input()
6+
for j in a:
7+
if j == '(':
8+
stack.append(j)
9+
elif j == ')':
10+
if stack:
11+
stack.pop()
12+
else: # 스택에 괄호가 없을경우 NO
13+
print("NO")
14+
break
15+
else: # break문으로 끊기지 않고 수행됬을경우 수행한다
16+
if not stack: # break문으로 안끊기고 스택이 비어있다면 괄호가 다 맞는거다.
17+
print("YES")
18+
else: # break안 걸렸더라도 스택에 괄호가 들어있다면 NO이다.
19+
print("NO")

0 commit comments

Comments
 (0)