Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
From wikipedia at http://en.wikipedia.org/wiki/Roman_numerals
Roman Numerals, as used today, are based on seven symbols:[1]
Symbol | Value |
---|---|
I | 1 |
V | 5 |
X | 10 |
L | 50 |
C | 100 |
D | 500 |
M | 1,000 |
Symbols are placed from left to right in order of value, starting with the largest. However, in a few specific cases, to avoid four characters being repeated in succession (such as IIII or XXXX) these can be reduced using subtractive notation as follows:
- the numeral I can be placed before V and X to make 4 units (IV) and 9 units (IX respectively)
- X can be placed before L and C to make 40 (XL) and 90 (XC respectively)
- C can be placed before D and M to make 400 (CD) and 900 (CM) according to the same pattern
Below are some examples of the modern use of Roman Numerals.
- 1954 as MCMLIV (Trailer for the movie The Last Time I Saw Paris)
- 1990 as MCMXC (The title of musical project Enigma's debut album MCMXC a.D., named after the year of its release.)
- 2014 as MMXIV - the year of the games of the XXII (22nd, Winter) Olympiad (in Sochi)
Solution
The solution takes advantage of string(int n, char c) instructor in C++, fill n consecutive copies of character c
No comments:
Post a Comment