Leetcode12 ---------- Integer to Roman
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Rome numeric rules: Reference wiki: http://zh.wikipedia.org/wiki/%E7%BD%97%E9%A9%AC%E6%95%B0%E5%AD%97
1. There are 7 roman numerals, namely, I (1), V (5), X (10), L (50), C (100), and D (500) and M (1000 ).
There is no "0" in the Roman numerals ".
2. Repeated times: a roman number can be repeated up to three times.
3. add and subtract from the right:
On the right side of a large number, remember a small number to indicate a large number and a small number.
On the left side of a large roman number, a small roman number is displayed, indicating that a large number reduces the number.
4. There is a limit on the number to be subtracted from the left, which is limited to I, X, and C. Only one number can be used on the left of a large number.
(*) The small numbers on the left of V and X can only be I.
(*) The small numbers on the left of L and C can only use X.
(*) The small numbers on the left side of D and M can only use C.
// LeetCode, Integer to Roman // time complexity O (num), space complexity O (1) class Solution {public: string intToRoman (int num) {const int radix [] = {1000,900,500,400,100, 90, 50, 40, 10, 9, 5, 4, 1}; const string symbol [] = {"M", "CM ", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV ", "I"}; string roman; for (size_t I = 0; num> 0; ++ I) {int count = num/radix [I]; num % = radix [I]; for (; count> 0; -- count) roman + = symbol [I] ;}return roman ;}};