The missing parenthesis

Description

Discuss (9 comments)
In an effort to help users who forget to put parenthesis around their expressions, we designed this puzzle to use artificial intelligence to find the most likely solution. The artificial assumption makes use of the common sense expression: Bigger is better.

The puzzle will take expressions of the form:
a op1 b op2 c
where
  • a, b, c are integers
  • op1, op2 are operators: +,- or *
The artificial intelligence assumes that parenthesis are missing, e.g. that the expression could have been written either (a op1 b) op2 c or a op1 (b op2 c). Knowing that humans make mistakes it decides to place the parenthesis so that the value of the expression is the biggest (remember, bigger is better).

Input Specifications

Your program must take one and only one command line argument: the input file.
The input file is formatted as follows:
  1. the first line contains the number n of expressions to evaluate
  2. the n following lines each contain an expression of the form
    a op1 b op2 c where
    • a, b, c are integers
    • op1, op2 are operators: +,- or *
Example:
5
2 - 9 * 8
6 * 8 + 1
9 + 10 - 9
7 - 7 + 7
5 * 5 * 3

Output Specifications

The output should be printed on the standard output (printf, etc...)
For each expression you should print its "bigger is better" value.

For the previous example:
-56
54
10
7
75
© CoderCharts - All Rights Reserved
Type Puzzle Pass 239 Fail 121
Scoring Language Level Easy Points 100
Tags arithmetic, expression evaluation, string manipulation

Source code editor

Unit Tests

Name CPU Unit Memory Unit

1000 expressions

This test has at 1000 expressions to evaluate
1s
250 MB

Confirm that you want to switch languages
Your current edits will be lost.

Confirm that you wish to load a previous submission
Your current edits will be lost.