编程介的小学生 2019-09-09 18:16 采纳率: 20.5%
浏览 272

罗马数字表达式,Roman Expressions

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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥30 用arduino开发esp32控制ps2手柄一直报错
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题