-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14888.py
47 lines (42 loc) · 1005 Bytes
/
14888.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#14888
from itertools import permutations
Max = -1000000000
Min = 1000000000
N = int(input())
num = list(map(int, input().split()))
oper_4 = list(map(int, input().split()))
oper = list()
for i in range(oper_4[0]):
oper.append('+')
for i in range(oper_4[1]):
oper.append('-')
for i in range(oper_4[2]):
oper.append('*')
for i in range(oper_4[3]):
oper.append('/')
allList = list(permutations(oper,N-1))
allList = list(set(allList))
x = 0
for i in range(len(allList)):
a = num[0]
for j in range(len(allList[i])):
b = num[j+1]
if allList[i][j] == "+":
a = a + b
elif allList[i][j] == "-":
a = a - b
elif allList[i][j] == "*":
a = a * b
elif allList[i][j] == "/":
if a < 0:
a = -a
a = a//b
a = -a
else:
a = a // b
if a > Max:
Max = a
if a < Min:
Min = a
print(Max)
print(Min)