leetcde 12 Integer to Roman

Posted 王坤1993

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcde 12 Integer to Roman相关的知识,希望对你有一定的参考价值。

class Solution {
public:
    string intToRoman(int num) {
        string res = "";
        vector<int> val{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        vector<string> str{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        for (int i = 0; i < val.size(); ++i) {
            while (num >= val[i]) {
                num -= val[i];
                res += str[i];
            }
        }
        return res;
    }
};

以上是关于leetcde 12 Integer to Roman的主要内容,如果未能解决你的问题,请参考以下文章

12. Integer to Roman

12 Integer to Roman

12. Integer to Roman

12. Integer to Roman

Leetcode 12——Integer to Roman

12. Integer to Roman 整数转罗马数字