F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Roman Expressions

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 221    Accepted Submission(s): 22


Problem Description
As any other marketing company, ACM produces a lot of funky advertising items that may contain a logo and be given to customers and business partners as small gifts. A unique specialty of ACM is a calculator that uses roman numbers.

Roman numbers are able to express any non-negative integer using uppercase letters:

Numbers are created by appending several letters together, the letter representing a higher value must always precede letters with lower values. The only exception are the letters ˇ°Iˇ±, ˇ°Xˇ±, and ˇ°Cˇ±, they may be used before higher letters to form values expressed by digits 4 and 9. The only possible combinations are:

Any roman number must first express thousands, then hundreds, tens, and ones. Therefore, 499 must 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
The input will consist from commands, each written on a separate line. Possible commands are
assignments, ˇ°RESETˇ±, and ˇ°QUITˇ±.
An assignment command starts with a single digit representing one of ten registers that the
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
minus (ˇ°-ˇ±) signs. You may assume that the expression will always be valid and no longer than
10000 characters.
 

Output
For each command, output a single line. For assignments, print the register name, equal sign,
and 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
is negative or larger than 10000. In such cases, no change to register values is made.
For RESET commands, invalidate all previous register assignments and print the word ˇ°Readyˇ±.
The QUIT command will be the last one. Print the word ˇ°Byeˇ± and terminate the program.
 

Sample Input
1=MC+IV-X 1=1+1 RESET 1=1+X 1=MM 1=1+1+1+1+1 2=1+1 QUIT
 

Sample Output
1=MXCIV 1=MMCLXXXVIII Ready Error 1=MM 1=MMMMMMMMMM Error Bye
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-23 00:30:17, Gzip enabled