forked from ndb796/Fast_Campus_Algorithm_Lecture_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[06]_3.py
30 lines (28 loc) · 744 Bytes
/
[06]_3.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
import copy
def recursive(array, n):
if len(array) == n:
operators_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):
operators_list = []
n = int(input())
recursive([], n - 1)
integers = [i for i in range(1, n + 1)]
for operators in operators_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)
print()