Integer to Roman

Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

思路:

暂时没有请参考这一个吧:http://blog.csdn.net/lanxu_yy/article/details/11703321?reload

class Solution {
public:
    string intToRoman(int num) {
        if(num<1)
            return NULL;
        char number[7]={'I','V','X','L','C','D','M'};
        int data[5];
        int nLength=0;
        string s;
        while(num!=0)
        {
            data[nLength++]=num%10;
            num/=10;
        }
        for(int i=nLength-1;i>=0;i--)
        {
            int skip=data[i]/5;
            int cur=data[i]%5;
            if(data[i]==5)                      //等于5的情况
            {
                s.push_back(number[2*i+1]);
            }
            else if(cur<=3)               //大于5小于9或者大于0小于4的情况
            {
                if(skip>0)
                {
                    s.push_back(number[2*i+1]);
                }
                for(int j=0;j<cur;j++)
                {
                    s.push_back(number[2*i]);
                }
            }
            else if(cur==4)            //等于9或者等于4的情况
            {
                s.push_back(number[2*i]);
                s.push_back(number[2*i+1+skip]);
            }
        }
        return s;
    }
};
原文地址:https://www.cnblogs.com/awy-blog/p/3592874.html