DWITE '09 R7 #4 - What is this Algebra?

View as PDF

Submit solution

Points: 12
Time limit: 1.0s
Memory limit: 64M

Problem type
DWITE Online Computer Programming Contest, 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 will contain 5 lines. Strings, no more than 255 characters in length, of well formed expressions.

The output will contain 5 integer answers to evaluated expressions.

Reminder: there are negative numbers.

Sample Input

2+-1
1 + 1 * 2
(((-1)))
1^1
(1- 3)^(-8 /2)

Sample Output

1
3
-1
11
24

Problem Resource: DWITE

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported

Comments


  • 0
    maxcruickshanks  commented on Dec. 6, 2024, 2:42 a.m.

    Since the original data were weak, an additional test case was added, and all submissions were rejudged. Data were provided by Mystical.