10233 - 和为零

请考虑一个由1到N(N=3, 4, 5 ... 9)的数字组成的递增数列:1 2 3 ... N。 现在请在数列中插入“+”表示加,或者“-”表示减,抑或是“ ”表示空白,来将每一对数字组合在一起(请不在第一个数字前插入符号)。 计算该表达式的结果并注意你是否得到了和为零。 请你写一个程序找出所有产生和为零的长度为N的数列。

输入

单独的一行表示整数N (3 <= N <= 9)。

输出

按照ASCII码的顺序,输出所有在每对数字间插入“+”, “-”, 或 “ ”后能得到和为零的数列。(注意:就算两个数字之间没有插入符号也应该保留空格)

样例

输入

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
1-2-3-4-5+6+7

提示

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.

PROGRAM NAME: zerosum INPUT FORMAT A single line with the integer N (3 <= N <= 9). SAMPLE INPUT (file zerosum.in) 7

OUTPUT FORMAT In ASCII order, show each sequence that can create 0 sum with a +', -', or ` ' between each pair of numbers. SAMPLE OUTPUT (file zerosum.out) 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

时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题