DWITE Online Computer Programming Contest

What is this Algebra?

May 2010
Problem 4

The idea is to take a simple mathematical expression and evaluate it, following the typical order of operations (brackets before multiplication before addition). Though since too many programming languages come with “evaluate this string as expression” functions, we’ll define our operations to be somewhat different.

The order will remain the same: Brackets, Exponents, Multiplication/Division, Addition/Subtraction.

The operations work as expected, with the exception of exponents. Exponents will concatenate the two sides as if they were strings. Both numbers being joined together are taken as their absolute values (that is, negative sign dropped). Whitespace is optional.

The input file DATA4.txt will contain 5 lines. Strings, no more than 255 characters in length, of well-formed expressions.

The output file OUT4.txt will contain 5 integer answers to evaluated expressions.

Reminder: There are negative numbers involved.

Sample Input:
1 + 1 * 2
(1- 3)^(-8 /2)
Sample Output: