Hermes Poseidon (HP) has produced a new calculator, the HP CXX, using the very latest in modern technology. It supports the four basic arithmetic operations on integer values from I to MMMMCMXCIX.
In this problem you simulate the HP CXX. Each line of input is one of the following:
+, -, *, or /, applied to the top two values of the stack.= operator, a request to print the value currently on top of the stack (in Roman numerals).The operators behave as follows. Let the topmost value be the first number and the value just below it be the second number.
+, *: push (second + first) or (second × first).-: push (second − first), i.e. subtract the first number from the second./: push (second ÷ first) using integer division, i.e. divide the second number by the first. If the divisor (the first number) is 0, print division by zero exception, then push the dividend (the second number) back onto the stack, but not the divisor.If an operator is requested but there are not enough numbers on the stack, print stack underflow and leave the stack unchanged. This applies both to the binary operators + - * / and to the print operator =.
If = is asked to print a value that is 0 or less, or greater than MMMMCMXCIX (4999), print out of range exception and move on to the next line of input.
Roman numerals. Each letter stands for a value:
| Roman numeral | Value |
|---|---|
| I | 1 |
| V | 5 |
| X | 10 |
| L | 50 |
| C | 100 |
| D | 500 |
| M | 1000 |
Letters written in sequence are added together, e.g. XXX = 10 + 10 + 10 = 30 and LXI = 50 + 10 + 1 = 61. When a smaller value is written before a larger one it is subtracted instead, e.g. IV = 5 − 1 = 4 and XC = 100 − 10 = 90. The usual rules apply:
Each line of input is one of:
+, -, *, /, or the print operator =.Input ends at end-of-file.
Produce one line per event, in the order the events occur:
= operation, the value on top of the stack written in Roman numerals.division by zero exceptionstack underflowout of range exceptionNo other output is produced.