
romanEquations
Being an avid student, Jim loves to read books for his Roman classes such as those by Dante and Cicero. One day, he came across a huge string of Roman numerals and realized that it made no sense. Since Jim also loves misteries, he figured that the string must contain a hidden equation.
Help Jim figure out what equation is hidden in the given RomanNumerals
. Only the following operators can be used:
- exactly one
=
sign; - exactly one of the operators
+
,-
,*
,/
, or%
to the left of=
.
Here are all valid Roman Numerals:
I = 1
V = 5
X = 10
L = 50
C = 100
D = 500
M = 1000
Anything above M will not be used in this challenge.
Make sure you understand how Roman numerals work, i.e.
IV = 4
IX = 9
etc.
Given RomanNumerals
, insert valid operators so that the obtained equation makes sense. If no answer can be found, return "not possible"
instead.
Example
- For
RomanNumerals = "MXIIICCCLXMCCCLXXIII"
, the output should beRomanEquations(RomanNumerals) = "MXIII+CCCLX=MCCCLXXIII"
, because1013 + 360 = 1373
.
Input/Output
-
[execution time limit] 0.5 seconds
-
[input] string RomanNumerals
The sequence of Roman numerals.
-
[output] string
It’s guaranteed that only one answer exists.
A valid equation written in Roman Numerals, or"not possible"
if it’s impossible to find one.
Post Comment