-
4949. 균형잡힌 세상Algorithm/Baekjoon 2023. 2. 6. 23:26
코드를 깔끔하게 짜고 싶은데 잘 안되고 있어서 답답하다.
이번에도 깔끔하게 짜려고 용쓰다가 풀이하는데 생각보다 오래 걸렸음...
문제의 조건을 조금 더 꼼꼼하게 보고 생각해서 풀자
import sys input = sys.stdin.readline def check(line) : pair = [] p = {')' : '(', ']' : '['} for c in line : if c == '(' or c == '[' : pair.append(c) elif (c == ')' or c == ']') : if len(pair) > 0 and (p[c] == pair[-1]) : pair.pop() else : return False if len(pair) == 0 : return True else : return False while True : line = input() if line.rstrip()=="." : break if check(line) : print("yes") else : print("no")
알고리즘 잘 하고 싶어요~
'Algorithm > Baekjoon' 카테고리의 다른 글
1918. 후위표기식 (0) 2023.02.07 1213. 팰린드롬 만들기 (0) 2023.02.07 9375. 패션왕 신해빈 (0) 2023.02.06 19583. 싸이버개강총회 (0) 2023.02.05 2002. 추월 (0) 2023.02.05