Roman Arithmetic

Problem #329

Tags: unlabeled

Who solved this?

No translations... yet

This problem was created by Clive Fraser - thanks a lot!

Everyone is familiar with Roman numerals but have you ever tried to do basic arithmetic using them? This problem is about using Roman numerals for simple addition and subtraction problems.

Most people know that the seven symbols have the following values: I = 1, V = 5, X = 10, L = 50, C = 100, D = 500 and M = 1000. There is a standard form for Roman numbers. This ensures that there is a unique representation for each of the numbers from 1 to 3999 inclusive. If you are unsure of the standard form definition there is a very clear explanation on Wikipedia at https://en.wikipedia.org/wiki/Roman_numerals.

The problems set, including the answers, will all use numbers in the range 1 to 3999. Only correct answers given in standard form will be accepted.

The first line of the problem will be a single integer N denoting the number of test cases. Each of the following N lines will hold a simple addition or subtraction, with the numbers given in Roman standard form. For each of these problems you must find the correct answer, also in Roman standard form. Give these answers, separated by spaces, as a single string.

Example:

input:
4
MMMDCCCLXXI - MMMCCCIII
DC + CCXLI
MMMCCCLIV - MMCCCXXXIX
MCXCVI + MCMLXXXII

answer:
DLXVIII DCCCXLI MXV MMMCLXXVIII
You need to login to get test data and submit solution.