TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

A calculator works with numbers of at most 90 digits long and computes expressions with the
following syntax:


::= | ()
::= + | - | * | /
::= an unsigned decimal integer number

The operators are: + (addition), - (subtraction), * (multiplication), and / (integer division, yielding
the quotient of the division). The calculator aborts the evaluation in the following cases: 1) a
division by zero; 2) the result of some operation is negative or exceeds 90 digits; 3) an input
number exceeds 90 digits.

Input Format

Write a program that simulates the calculator. For each expression read from an input text file,
the program prints the value of the expression starting from the beginning of an output line. If the
calculator aborts the evaluation of the expression, the word "Error" is printed as shown in the
input/output sample above. An expression can contain at most 90 operators and is syntactically
correct. White spaces are used freely in input that terminates with an end of file.

Output Format

Sample Input 1

(((100000000000 * 100000000000) / 5)-1) 
100 
(0*(1000000000000000000000000000000 * 
   (1000000000000000000000000000000 *  
    1000000000000000000000000000000))) 
((1-2)+1) 
(0*(1/0))

Sample Output 1

1999999999999999999999 
100 
Error 
Error 
Error

Hints

Problem Source

Migrated from old NTUJ.

SEERC 2010

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200