Created
January 9, 2020 04:01
-
-
Save inspirit941/48aaa5271ca2880786d78fc978bbc9b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
def check(brackets): | |
stack = [] | |
for i in brackets: | |
if i == "(": | |
stack.append(i) | |
else: | |
# ")" 를 입력받았는데 이전에 "("를 입력받은 적이 없는 경우. VPS가 아니다. | |
if not stack: | |
print("NO") | |
return | |
else: | |
# stack에 "("가 있으므로 stack에서 "("를 꺼낸다. | |
stack.pop() | |
# 괄호를 전부 다 돌았는데 stack 안에 무언가가 남아 있으면 VPS가 아니다. | |
if not stack: | |
print("YES") | |
return | |
else: | |
print("NO") | |
return | |
for _ in range(n): | |
brackets = input() | |
check(brackets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment