Integer to Roman
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Solution: Buffer the roman numbers.
1 class Solution { 2 public: 3 string rome[4][10] = {{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}, 4 {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}, 5 {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}, 6 {"", "M", "MM", "MMM"}}; 7 string intToRoman(int num) { 8 string res; 9 int i = 3; 10 while(num > 0) { 11 int div = (int)pow(10,i); 12 res += rome[i][num/div]; 13 i--; 14 num %= div; 15 } 16 return res; 17 } 18 };