-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4866_괄호검사.py
42 lines (35 loc) · 926 Bytes
/
4866_괄호검사.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# base_list = ['{', '}', '(', ')']
def check_bracket(arr):
stack = []
for item in arr:
if item == '(' or item == '{':
stack.append(item)
elif item == ')':
if stack == []:
return 0
elif stack[-1] == '(':
stack.pop()
else:
return 0
elif item == '}':
if stack == []:
return 0
elif stack[-1] == '{':
stack.pop()
else:
return 0
if stack == []:
return 1
else:
return 0
test_num =int(input())
for t in range(test_num):
test_case = list(input())
# new_list = []
# for item in test_case:
# if item in base_list:
# new_list.append(item)
# print(new_list)
result = check_bracket(test_case)
print('#' + str(t+1) +' ', end='')
print(result)