Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
1:分清各种情况
string intToRoman(int num)
{
if(num <= 0)
{
return "";
}
string result = "";
int tmpArray[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
map<int, string> myMap;
myMap[1000] = "M";
myMap[900] = "CM";
myMap[500] = "D";
myMap[400] = "CD";
myMap[100] = "C";
myMap[90] = "XC";
myMap[50] = "L";
myMap[40] = "XL";
myMap[10] = "X";
myMap[9] = "IX";
myMap[5] = "V";
myMap[4] = "IV";
myMap[1] = "I";
for(int i = 0; i < 13; i++)
{
while(num >= tmpArray[i])
{
result.append(myMap[tmpArray[i]]);
num -= tmpArray[i];
}
}
return result;
}