-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7490.py
More file actions
39 lines (27 loc) · 733 Bytes
/
7490.py
File metadata and controls
39 lines (27 loc) · 733 Bytes
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
import copy
def recursive(array, n):
if len(array) == n:
operator_list.append(copy.deepcopy(array))
return
array.append(' ')
recursive(array, n)
array.pop()
array.append('+')
recursive(array, n)
array.pop()
array.append('-')
recursive(array, n)
array.pop()
test_case = int(input())
for _ in range(test_case):
operator_list = []
n = int(input())
recursive([], n-1)
integers = [i for i in range(1, n+1)]
for operators in operator_list:
string = ""
for i in range(n-1):
string += str(integers[i]) + operators[i]
string += str(integers[-1])
if eval(string.replace(" ","")) == 0:
print(string)