파이썬/백준

python ) 백준 #1541 잃어버린 괄호

채린.__. 2022. 10. 17. 18:46

 

<정답>

# - 가 나오면 뒷부분 다 빼주면 된다. - 기준으로 나눠서 입력받음
formula = input().split("-")
answear = 0

#첫번째 덩어리에서 + 기준으로 숫자를 나눠주고 다 더한다.
for i in formula[0].split('+'):
    answear += int(i)

#뒷부분은 다 빼주면 됨.
for i in formula[1:]:
    for j in i.split('+'):
        answear -= int(j)
print(answear)