## CCC '96 S4 - When in Rome

View as PDF

Points: 10
Time limit: 2.0s
Memory limit: 64M

Problem type
##### 1996 Canadian Computing Competition, Stage 1, Problem D

If the Roman Empire had not fallen, then Rome would surely have discovered electricity and used electronic calculators; however, the Romans used Roman Numerals! Your task is to implement a simple Roman Calculator which accepts two Roman Numerals and outputs the sum in Roman Numerals. You may assume that numbers greater than 1000 will not occur in the input. Output numbers greater than 1000 are illegal and should generate the message CONCORDIA CUM VERITATE (In Harmony with Truth).

The input consists of a number, indicating the number of test cases, followed by this many test cases. Each test case consists of a single line with two numbers in Roman Numerals separated by a + along with an = at the end. There are no separating spaces.

For each test case the output is a copy of the input with the Roman Numeral that represents the sum. Outputs for different test cases are separated by a blank line.

#### Roman Research

The Roman Numerals used by the Romans evolved over many years, and so there are some variations in the way they are written. We will use the following definitions:

1. The following symbols are used: I for 1, V for 5, X for 10, L for 50, C for 100, D for 500, and M for 1000.
2. Numbers are formed by writing symbols from 1. from left to right, as a sum, each time using the symbol for the largest possible value. The symbols M, C, X, or I may be used at most three times in succession. Only if this rule would be violated, you can use the following rule:
• When a single I immediately precedes a V or X, it is subtracted. When a single X immediately precedes an L or C, it is subtracted. When a single C immediately precedes a D or M, it is subtracted. For example: II = 2; IX = 9; CXIII = 113; LIV = 54; XXXVIII = 38; XCIX = 99.

#### Sample Input

3
VII+II=
XXIX+X=
M+I=

#### Sample Output

VII+II=IX
XXIX+X=XXXIX
M+I=CONCORDIA CUM VERITATE

CCC problem statements in large part from the PEG OJ

• Narcariel  commented on Sept. 13, 2019, 12:22 p.m.

I am outputting the right and exact answer and it is giving me a WA? Help pls

• tzak_el  commented on Sept. 13, 2019, 2:46 p.m.

I've tested a few of your recent submissions, and none of them pass the sample input provided. I would recommend running your code through the sample input on your own to figure out what's wrong.

• Narcariel  commented on Sept. 14, 2019, 5:22 p.m.

Lol I lied something wrong withda output.

• Zafirua  commented on March 2, 2019, 3:38 p.m. edit 2

Removed Comment

• Ninjaclasher  commented on June 12, 2017, 9:12 p.m.

For example, if it was IIX, would that be 10, or 12? I find the problem statement about this section a bit confusing.

• Kirito  commented on June 12, 2017, 10:51 p.m.

IIX is not a valid Roman Numeral.

• Dordor1218  commented on March 18, 2018, 10:31 a.m. edited

I'm still kind of confused why it isn't a roman numeral? Update: never mind i found out why

• PaulOlteanu  commented on July 5, 2015, 9:36 p.m. edit 3

DMOJ output is different from my local machine.

Screenshot

Have I hardcoded too much for my submission to be illegitimate?