B |
Evaluate the Expression Input: Standard Input Output: Standard Output |
In this problem, we will consider a mathematical expression according to the following BNF grammar:
<expression> = <variable> | <expression><operator><expression>| “(“<expression>“)”
<operator> = “+” | “*”
<variable> = “a” | “b” | “c” | … | “y” | “z”
When evaluating such expressions, you have to follow the conventional rules. That means you have to do things in the brackets first and multiplications have to be done before addition.
Example: 2*(3+4*2) = 22
Given an expression and some inequalities, you have to assign each variable with a positive integer so that the value of the expression is minimized.
Consider an example:
Expression = a+b*c and Inequalities = a>b, c>b
Assignment of: a=2, b=1 and c=2 will give us the minimum value. => 2 + 1*2