Integer to Roman

Code:

class Solution {
public:
    string intToRoman(int num) {
        string roman;
        int nums[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        char symbols[13] = {'M', 'C', 'D', 'C', 'C', 'X', 'L', 'X', 'X', 'I', 'V', 'I', 'I'};
        for(int i=0;num>0;i++){
            int tmp=num/nums[i];
            num=num-tmp*nums[i];
            while(tmp>0){
                roman.append(1,symbols[i]);
                if(i%2)
                    roman.append(1,symbols[i-1]);
                tmp--;
            }
        }
        return roman;
    }
};
原文地址:https://www.cnblogs.com/winscoder/p/3395938.html