๋ฐ์ํ
๐ป ๋ฐฑ์ค 1541๋ฒ [์์ด๋ฒ๋ฆฐ ๊ดํธ]
ํ์ด)
# ์ต์ข ์ ์ถ import re eq = input() num_lst = re.split('[+|-]',eq) stack = [] stack.append(int(num_lst[0])) i = 1 for ch in eq : if ch.isnumeric() == False : if ch == '+' : stack.append(int(stack.pop()) + int(num_lst[i])) else : stack.append(int(num_lst[i])) i+=1 print(stack) res = stack[0] for i in range(1,len(stack)) : res -= stack[i] print(res) # ==> ๋ฉ๋ชจ๋ฆฌ : 330K4B, ์๊ฐ : 140ms, ์ฝ๋๊ธธ์ด : 388B
728x90
๋ฐ์ํ
'๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค > greedy' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 1931] [greedy] ํ์์ค ๋ฐฐ์ โ (0) | 2021.04.18 |
---|---|
[๋ฐฑ์ค 11047] [greedy] ๋์ 0 (0) | 2021.04.17 |
[๋ฐฑ์ค 11399] [greedy] ATM (0) | 2021.04.17 |
[๋ฐฑ์ค 2839] [greedy] ์คํ๋ฐฐ๋ฌ (0) | 2021.04.17 |