DWITE '08 R1 #4 - What is this Roman Numeral

View as PDF

Submit solution

Points: 7
Time limit: 1.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
DWITE Online Computer Programming Contest, October 2008, Problem 4

Although today's use of roman numerals is typically limited to movie titles or pages preceding the main part of a book (and thus are typically small), lets build a Roman-to-Decimal converter anyway. Just for the LOLs.

The input will contain 5 lines, Roman Numerals with values 1 \leq N \leq 2000

The output will contain 5 lines, decimal values of the input numbers.

For your reference, symbols are as follows:

I 1
V 5
X 10
L 50
C 100
D 500
M 1000

Numbers in between the symbols are constructed by adding the symbols together (II for 2); or subtracting, by placing a smaller symbols, in front of a larger one (IV for 4).

Note: be cautious that the numbers are slightly more complicated than simply adding the values of symbols in order. While XI XII XIII (11, 12, 13) are simple enough, XIV (14) breaks the patterns (that is, it is not 10 + 1 + 5, but 10 + (5 - 1))

Sample Input


Sample Output


Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Problem Resource: DWITE


There are no comments at the moment.