๋ฌธ์
https://www.acmicpc.net/problem/4949
4949๋ฒ: ๊ท ํ์กํ ์ธ์
ํ๋ ๋๋ ์ฌ๋ฌ์ค์ ๊ฑธ์ณ์ ๋ฌธ์์ด์ด ์ฃผ์ด์ง๋ค. ๊ฐ ๋ฌธ์์ด์ ์๋ฌธ ์ํ๋ฒณ, ๊ณต๋ฐฑ, ์๊ดํธ("( )") ๋๊ดํธ("[ ]")๋ฑ์ผ๋ก ์ด๋ฃจ์ด์ ธ ์์ผ๋ฉฐ, ๊ธธ์ด๋ 100๊ธ์๋ณด๋ค ์๊ฑฐ๋ ๊ฐ๋ค. ๊ฐ ์ค์ ๋ง์นจํ(".")๋ก ๋๋๋ค
www.acmicpc.net
ํ์ด
# ๋ฐฑ์ค 4949๋ฒ ๋ฌธ์ - ๊ท ํ์กํ ์ธ์
bracket = ['(','[',')',']']
while True:
stack = []
string = input()
if string == '.':
break
for s in string:
if s in bracket: # ๊ดํธ๊ฐ ์์ ๊ฒฝ์ฐ
if len(stack) == 0:
stack.append(s)
continue
if s == ')' and stack[-1] == '(':
stack.pop()
continue
elif s == ']' and stack[-1] == '[':
stack.pop()
continue
stack.append(s)
if len(stack):
print('no')
else:
print('yes')
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] [Python] Class3_1012๋ฒ_์ ๊ธฐ๋ ๋ฐฐ์ถ (0) | 2022.10.26 |
---|---|
[๋ฐฑ์ค] [Python] 10799๋ฒ_์ ๋ง๋๊ธฐ_์คํ (0) | 2022.10.26 |
[๋ฐฑ์ค] [Python] 1966๋ฒ_ํ๋ฆฐํฐ ํ_ํ,๋ฑ (0) | 2022.10.14 |
[๋ฐฑ์ค] [Python] 2164๋ฒ_์นด๋2_ํ,๋ฑ (0) | 2022.10.14 |
[๋ฐฑ์ค] [Python] 10773๋ฒ_์ ๋ก_์คํ (1) | 2022.10.13 |