programmers.co.kr/learn/courses/30/lessons/67257
from itertools import permutations
import re
def solution(s):
number_s = re.split("\W+",s)
oper_s = re.split("\d+",s)
index=1
for i in range(1,len(oper_s)-1):
number_s.insert(index,oper_s[i])
index+=2
answer=0
oper=['+','-','*']
oper_combi = list(permutations(oper, len(oper)))
for o in oper_combi:
number_c=[]
for i in range(len(number_s)):
number_c.append(number_s[i])
for op in o:
index=0
while index<len(number_c):
if number_c[index]==op:
number_c[index-1] = eval(str(number_c[index-1])+op+str(number_c[index+1]))
number_c.pop(index)
number_c.pop(index)
index=index-1
else:
index+=1
answer=max(answer,abs(number_c[0]))
return answer
'코딩 테스트 > 문제 풀기' 카테고리의 다른 글
[프로그래머스] 프린터 (0) | 2021.03.24 |
---|---|
[프로그래머스] 멀쩡한 사각형 (0) | 2021.03.24 |
[프로그래머스] 짝지어 제거하기 (0) | 2021.03.23 |
[프로그래머스] N개의 최소공배수 (0) | 2021.03.23 |
[프로그래머스] JadenCase 문자열 만들기 (0) | 2021.03.23 |
댓글