- Input file: expr.in
- Output file: expr.out
- Time limit: 2 seconds
- Memory limit: 64 Megabytes
other marketing company, ACM produces a lot of funky advertising items that
a logo and be given to customers and business partners as small gifts. A unique
is a calculator that uses roman numbers.
numbers are able to express any non-negative integer using uppercase
are created by appending several letters together, the letter representing a
always precede letters with lower values. The only exception are the letters
"I", "X", and
they may be used before higher letters to form values expressed by digits 4 and
9. The only
possible combinations are:
roman number must first express thousands, then hundreds, tens, and ones.
always be written as "CDXCIX", not "ID".
Although not very practical, this gift is considered extremely
"cooooool". Your task is to write
software for that calculator.
input will consist from commands, each written on a separate line. Possible
assignments, "RESET", and "QUIT".
assignment command starts with a single digit representing one of ten registers
calculator has. The register number is followed by an equal sign ("=")
and an expression. The
expression will consist only from valid roman numbers, register names
(digits), plus ("+") and
("-") signs. You may assume that the expression will always be valid and no
each command, output a single line. For assignments, print the register name,
the value that is being assigned to that register. Instead of it, print the word
"Error", if the
expression contains a reference to a register that has not been
assigned before, or if the result
negative or larger than 10000. In such cases, no change to register values is
RESET commands, invalidate all previous register assignments and print the word
QUIT command will be the last one. Print the word "Bye" and terminate the
for Sample Input