Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
class Solution { public: string intToRoman(int num) { map<int,string> mp = {{1000,"M"},{900,"CM"},{500,"D"}, {400,"CD"},{100,"C"},{90,"XC"},{50,"L"},{40,"XL"},{10,"X"}, {9,"IX"},{5,"V"},{4,"IV"},{1,"I"}}; string res; for(auto iter=mp.rbegin();iter!=mp.rend();++iter){ while(num-iter->first>=0){ res += iter->second; num -= iter->first; } } return res; } };
原文地址:http://blog.csdn.net/guorudi/article/details/45648807