2832. Zero

单点时限: 2.0 sec

内存限制: 256 MB

Let‘s consider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 … N. Now insert either a '+' for addition or a '-' for subtraction or a ' ' [blank] to run the digits together, between each pair of digits (not in front of the first digit). Calculate the result that of the expression and see if you get zero.

Write a program that will find all sequences of length N that produce a zero sum.

输入格式

The first line of the input contains the number of test cases (<10). Single test case is represented by single line that contains the integer N (3 <= N <= 9).

输出格式

For each test case in ASCII order, print each sequence that can create 0 sum with a '+', '-', or ' ' (space) between each pair of numbers. Space shows that the digits run together. Different test cases should be separated by an empty line.

样例

Input
2
3
7
Output
1+2-3
1+2-3+4-5-6+7
1+2-3-4+5+6-7
1-2 3+4+5+6+7
1-2 3-4 5+6 7
1-2+3+4-5+6-7
1-2-3-4-5+6+7

25 人解决,32 人已尝试。

28 份提交通过,共有 52 份提交。

4.1 EMB 奖励。

创建: 14 年,2 月前.

修改: 7 年,3 月前.

最后提交: 1 年,5 月前.

来源: Ukrainian

题目标签