C-PROM 2014 (PROBLEM 10 :DECODING ROMAN NUMERALS)



PROBLEM 10 : DECODING ROMAN NUMERALS


The roman people uses the Roman Numerals for base 10 numbers. Each numeral-character such as I, V, X, L, C, D and M has a single value such as 1, 5, 10, 50, 100, 500 and 1000 respectively. The value of Roman Numerals is the sum of its numeral-characters unless a smaller numeral-character is placed in front of larger numeral-character, in which case the smaller numeral-character is subtracted from the total. For instance VI = 5 + 1, while IV = 5 – 1. You may assume that at most one subtraction is required per number.

Input
Input are in the form of text string for roman numerals, separated by a single space in a single line.

Output
For each roman numerals, print the number in base 10 numbers at a single line.


Sample Input
Sample Output
IV LXI CLV DI MDCLXVII
4
61
155
501
1667



Problem Setter : Jamal Othman, UiTM Pulau Pinang




Share this

Related Posts

Previous
Next Post »