12. Integer to Roman
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
12. Integer to Roman
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
class Solution {
public:
string intToRoman(int num) {
string m[4] = {"", "M", "MM", "MMM"},
c[10] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"},
x[10] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"},
i[10] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
return m[num/1000]+c[(num%1000)/100]+x[(num%100)/10]+i[num%10];
}
};