TopCoder problem "Expressions" used in SRM 10 (Division I Level Two , Division II Level Two)

Problem Statement

Class Name: Expressions
Method Name: evaluate
Parameters: String
Returns: int

Implement a class Expressions, which contains a method evaluate.  The method
takes a String as a parameter representing a mathematic expression and returns
the int that is is equivalent to the expression.

The expression contains non-negative integers and the operands *, +, - , /, and
parenthesis ( ). There is no white space in the expression.  The division (/)
is integer division (that is any remainder is truncated). Remember: Parentheses
are highest priority, then * and / are medium priority, then + and - are the
lowest priority.  When there are parentheses inside parentheses, the inner
parentheses are evaluated first.  When dealing with operands of equal priority,
evaluation occurs from left to right.

Here is the method signature.
public int evaluate(String expression);

expression is of length between 1 and 50.  It contains digits and the symbols
*, +, -, /, (, ) and represents a valid expression with no division by 0
(TopCoder will check this).

"6+2*(3*(1+1))-6/(2+3)" -> 17.


Method signature:int evaluate(String param0)
(be sure your method is public)

Problem url:

Problem stats url:




Problem categories: