LeetCode 12. Integer to Roman

来源:互联网 发布:wps数据有效性设置取消 编辑:程序博客网 时间:2024/06/06 18:44

描述

把数字转换成罗马数字

解决


class Solution {public:    string intToRoman(int num) {        int arr[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5,4, 1};        string str[13] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};        string res;        int i = 0;        while (num)        {            int t = num / arr[i];            num %= arr[i];            while (t)            {                res += str[i];                --t;            }            ++i;        }        return res;    }};
0 0
原创粉丝点击