import sys
while True:
string = sys.stdin.readline().rstrip()
if string == '.':
break
stack = []
flag = 1
for cha in string:
if cha == '(' or cha == '[':
stack.append(cha)
elif cha == ')':
if stack and stack[-1] == '(':
stack.pop()
else:
flag = 0
break
elif cha == ']':
if stack and stack[-1] == '[':
stack.pop()
else:
flag = 0
break
if not stack and flag == 1:
print('yes')
else:
print('no')
import sys
import sys
string = sys.stdin.readline()
string.rstrip()
sys.stdin.readline()
은 줄 단위로 입력받으며 input()
보다 빠르다.
rstrip()
은 오른쪽 공백을 제거해준다.
sys.stdin.readline()
<input>
12 3 45
<output>
1
2
3
4
5
sys.stdin.readline().split()
<input>
12 3 45
<output>
12
3
45
sys.stdin
<input>
1234
<output>
1234
<input>
hello?
<output>
hello?
...
배열의 not
temp = []
if temp: // len(temp) > 0
if not temp: // len(temp) = 0