码迷,mamicode.com
首页 > 其他好文 > 详细

leetcde 12 Integer to Roman

时间:2017-02-04 01:05:58      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:etc   ++   while   cto   vector   rom   roman   int   str   

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

标签:etc   ++   while   cto   vector   rom   roman   int   str   

原文地址:http://www.cnblogs.com/wangkun1993/p/6363847.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!