https://www.acmicpc.net/problem/4949
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
while True:
answer = 'yes'
s=input()
if s=='.':
break
stack=[]
for i in s:
if i=='(' or i=='[':
stack.append(i)
if i==')':
if len(stack) != 0 and stack[-1] =='(':
stack.pop()
else:
stack.append(i)
elif i==']':
if len(stack) != 0 and stack[-1] =='[':
stack.pop()
else:
stack.append(i)
if len(stack) != 0:
answer ="no"
print(answer)
|
cs |
스택을 사용하는 문제고 조건문을 합치려고 괄호들 아스키코드를 보니 합치기어려워 그냥 쪼갰다..
Using Stack, First time I think just one if clause, and Find those ascii code of brackets.. but not easy
And then just two if clause
print(ord('('))
print(ord(')'))
print(ord('['))
print(ord(']'))
반응형
'python-algorithm' 카테고리의 다른 글
백준 18258 큐 2 (0) | 2022.11.09 |
---|---|
백준 1620 나는야 포켓몬 마스터 이다솜 (0) | 2022.11.09 |
백준 18398 HOMWRK (0) | 2022.11.09 |
백준 1966 프린터 큐 (0) | 2022.11.08 |
백준 10816 숫자 카드 2 (0) | 2022.11.08 |
댓글