[baekjoon]python #4949 ๊ท ํ์กํ ์ธ์
https://www.acmicpc.net/problem/4949
4949๋ฒ: ๊ท ํ์กํ ์ธ์
ํ๋ ๋๋ ์ฌ๋ฌ์ค์ ๊ฑธ์ณ์ ๋ฌธ์์ด์ด ์ฃผ์ด์ง๋ค. ๊ฐ ๋ฌธ์์ด์ ์๋ฌธ ์ํ๋ฒณ, ๊ณต๋ฐฑ, ์๊ดํธ("( )") ๋๊ดํธ("[ ]")๋ฑ์ผ๋ก ์ด๋ฃจ์ด์ ธ ์์ผ๋ฉฐ, ๊ธธ์ด๋ 100๊ธ์๋ณด๋ค ์๊ฑฐ๋ ๊ฐ๋ค. ๊ฐ ์ค์ ๋ง์นจํ(".")๋ก ๋๋๋ค
www.acmicpc.net
while True:
a=input()
stack=[]
flag=1
if a=='.':
break
for i in a:
if i=='[' or i=='(':
stack.append(i)
elif i==']':
if len(stack) !=0 and stack[-1] =='[':
stack.pop()
else:
stack.append(']')
flag=0
break
elif i==')':
if len(stack) !=0 and stack[-1] == '(':
stack.pop()
else:
stack.append(')')
flag=0
break
print('yes' if flag and not(stack) else 'no')
'Problem Solving > BAEKJOON' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[baekjoon]python #17298 ์คํฐ์ (0) | 2022.08.31 |
---|---|
[baekjoon]python #2108 ํต๊ณํ (0) | 2022.06.24 |
[baekjoon]python #1966 ํ๋ฆฐํฐ ํ (0) | 2022.06.23 |
[baekjoon]python #2805 ๋๋ฌด ์๋ฅด๊ธฐ (0) | 2022.06.23 |
[baekjoon]python #1874 ์คํ ์์ด (0) | 2022.06.23 |
๋๊ธ