编程介的小学生 2019-04-04 01:04 采纳率: 20.5%
浏览 203

用罗马数字构成的表达式的计算问题,怎么采用C语言程序的设计的思路来实现

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 Arcgis相交分析无法绘制一个或多个图形
    • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
    • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题
    • ¥20 云服务Linux系统TCP-MSS值修改?
    • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)