[Solution] Maximum Expression CodeChef Solution
Problem
You are given a string of length , consisting of the digits 0-9
and the characters '+'
and '-'
. represents a valid mathematical expression.
Rearrange the characters of to form a valid mathematical expression such that the result obtained upon evaluating it is maximum.
If there are multiple possible answers, you may print any of them.
Note: A string of length is said to be a valid mathematical expression if the following hold:
- The first character of is not
+
or-
. - The last character of is not
+
or-
. - Any
+
or-
in must not be adjacent to another+
or-
.
In particular, numbers are allowed to have leading zeros, and adding/subtracting zero is fine.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of lines of input.
- The first line of each test case contains a single integer , denoting the size of the string.
- The second line of each test case contains the string .
Output Format
For each test case, output on a new line the rearranged string giving the maximum value upon evaluation. If there are multiple possible answers, you may print any of them.
Explanation:
Test case : The given output expression evaluates to , which is the maximum possible.
Test case : The given output expression evaluates to , which is the maximum possible.
Test case : The given output expression evaluates to , which is the maximum possible.
No comments:
Post a Comment