310031: CF1774A. Add Plus Minus Sign

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Add Plus Minus Sign

题意翻译

在一些 $0$ 与 $1$ 之间添加 +/- 号,求一种方案使得最终结果绝对值最小。

题目描述

AquaMoon has a string $ a $ consisting of only $ 0 $ and $ 1 $ . She wants to add $ + $ and $ - $ between all pairs of consecutive positions to make the absolute value of the resulting expression as small as possible. Can you help her?

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \leq t \leq 2\,000 $ ) – the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $ n $ ( $ 2 \leq n \leq 100 $ ) — the length of $ a $ . The second line of each test case contains a string $ a $ of length $ n $ , consisting of only $ 0 $ and $ 1 $ .

输出格式


For each test case, output a string of length $ n - 1 $ consisting of $ - $ and $ + $ on a separate line. If there is more than one assignment of signs that produces the smallest possible absolute value, any of them is accepted.

输入输出样例

输入样例 #1

3
2
11
5
01101
5
10001

输出样例 #1

-
+-++
+++-

说明

In the first test case, we can get the expression $ 1 - 1 = 0 $ , with absolute value $ 0 $ . In the second test case, we can get the expression $ 0 + 1 - 1 + 0 + 1 = 1 $ , with absolute value $ 1 $ . In the third test case, we can get the expression $ 1 + 0 + 0 + 0 - 1 = 0 $ , with absolute value $ 0 $ .

Input

题意翻译

在一些 $0$ 与 $1$ 之间添加 +/- 号,求一种方案使得最终结果绝对值最小。

Output

**题意翻译**

在一些 0 与 1 之间添加 +/- 号,求一种方案使得最终结果绝对值最小。

**题目描述**

AquaMoon 有一个只包含 0 和 1 的字符串 a。她想在所有相邻位置之间添加 + 和 - 号,使得结果表达式的绝对值尽可能小。你能帮她吗?

**输入输出格式**

**输入格式**

第一行包含一个整数 t (1 ≤ t ≤ 2,000) – 测试用例的数量。接下来是测试用例的描述。

每个测试用例的第一行包含一个整数 n (2 ≤ n ≤ 100) — 字符串 a 的长度。

每个测试用例的第二行包含一个长度为 n 的字符串 a,由 0 和 1 组成。

**输出格式**

对于每个测试用例,输出一个长度为 n - 1 的字符串,由 - 和 + 组成。如果有多个符号分配方案可以得到最小的绝对值,则任何一个都是可接受的。

**输入输出样例**

**输入样例 #1**

```
3
2
11
5
01101
5
10001
```

**输出样例 #1**

```
-
+-++
+++-
```

**说明**

在第一个测试用例中,我们可以得到表达式 1 - 1 = 0,其绝对值为 0。

在第二个测试用例中,我们可以得到表达式 0 + 1 - 1 + 0 + 1 = 1,其绝对值为 1。

在第三个测试用例中,我们可以得到表达式 1 + 0 + 0 + 0 - 1 = 0,其绝对值为 0。**题意翻译** 在一些 0 与 1 之间添加 +/- 号,求一种方案使得最终结果绝对值最小。 **题目描述** AquaMoon 有一个只包含 0 和 1 的字符串 a。她想在所有相邻位置之间添加 + 和 - 号,使得结果表达式的绝对值尽可能小。你能帮她吗? **输入输出格式** **输入格式** 第一行包含一个整数 t (1 ≤ t ≤ 2,000) – 测试用例的数量。接下来是测试用例的描述。 每个测试用例的第一行包含一个整数 n (2 ≤ n ≤ 100) — 字符串 a 的长度。 每个测试用例的第二行包含一个长度为 n 的字符串 a,由 0 和 1 组成。 **输出格式** 对于每个测试用例,输出一个长度为 n - 1 的字符串,由 - 和 + 组成。如果有多个符号分配方案可以得到最小的绝对值,则任何一个都是可接受的。 **输入输出样例** **输入样例 #1** ``` 3 2 11 5 01101 5 10001 ``` **输出样例 #1** ``` - +-++ +++- ``` **说明** 在第一个测试用例中,我们可以得到表达式 1 - 1 = 0,其绝对值为 0。 在第二个测试用例中,我们可以得到表达式 0 + 1 - 1 + 0 + 1 = 1,其绝对值为 1。 在第三个测试用例中,我们可以得到表达式 1 + 0 + 0 + 0 - 1 = 0,其绝对值为 0。

加入题单

算法标签: