Original title Link: https://oj.leetcode.com/problems/integer-to-roman/
This is also a simple question, the focus is to maintain an array of Roman numerals, and then each bit of computing time, then the array back 2 bits, using the same calculation method to get the current bit of the Roman expression.
Class Solution {public: string inttoroman (int num) { char map[7] = {' I ', ' V ', ' X ', ' L ', ' C ', ' D ', ' M '}; string res = ""; int shift = 0; while (num) { int cur = num%; res = GETSTR (map + SHIFT, cur) + res; Num/= ten; SHIFT + = 2; } return res; } String Getstr (char map[], int num) { string res = ""; if (num > 0 && num < 4) { res.append (num, map[0]); } else if (num = = 4) { res.append (1, map[0 ]); Res.append (1, map[1]); } else if (num = = 5) { res.append (1, map[1]); } else if (num > 5 && num < 9) { res.append (1, MA P[1]); Res.append (num-5, map[0]); } else if (num = = 9) { res.append (1, map[0]); Res.append (1, map[2]); } return res; }};
[Leetcode] 12-integer to Roman