알고리즘/소스코드
KOREATECH 1015: 괄호 짝
cjw.git
2020. 12. 9. 11:12
Link : judge.koreatech.ac.kr/problem.php?id=1015
Python
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
from sys import stdin
quest_count = int(stdin.readline().strip())
for i in range(quest_count):
quest_data = stdin.readline().strip()
stack = []
for s in quest_data:
if s in ('(','{','['):
stack.append(s)
elif s in (')','}',']'):
if len(stack) == 0:
print('no')
break
else:
left = stack.pop()
if(s == ')' and left != '(') or \
(s == ']' and left != '[') or \
(s == '}' and left != '{'):
print('no')
break
else:
print('yes' if len(stack) == 0 else 'no')
|
cs |
FeedBack
cjw.git@gmail.com