백준 :: 잃어버린 괄호 <1541번>

혜 콩·2021년 5월 21일
0

알고리즘

목록 보기
3/61

> 문제 <


출처 : https://www.acmicpc.net/problem/1541

> 아이디어 <

55-35+22+11-14+22
----> 55-(35+22+11)-(14+22) == 55-(35+22+11+14+22)
앞의 수 - 뒤의 +로 묶인 수들의 합 (마이너스를 만날 때 가장 큰 수 빼기)

> 코드 <

#import re

#a = re.split('[+-]', input())

a=input().split('-')

nums=[]
for i in a:
  result=0
  s = i.split('+')
  for j in s:
    result += int(j)
  nums.append(result)
n = nums[0]
for i in range(1,len(nums)):
  n -= nums[i]
print(n)
profile
배우고 싶은게 많은 개발자📚

0개의 댓글