[그리디 - 1541번] 잃어버린 괄호

Jeong Ha Seung·2022년 1월 21일

expression = input().split('-')  # 최솟값을 만들기 위해 "-"를 기준으로 분리하면 된다.
result = 0

# 수식이 주어졌을 때 "+"를 기준으로 해서 우선적으로 더한다.
for i in map(int, expression[0].split('+')):
    result += i


for i in expression[1:]:  # 인덱스 1 이후부터 끝까지
    result -= sum(map(int, i.split('+')))

print(result)
profile
블로그 이전했습니다. https://morethan-haseung-log.vercel.app

0개의 댓글