Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
最开始的我还是太天真了。我甚至以为罗马符号只有X,V,I
我还是图simple啊……
“M”,”CM”,”D”,”CD”,”C”,”XC”,”L”,”XL”,”X”,”IX”,”V”,”IV”,”I”
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1
我的心好痛。
C# Code
public class Solution
{
public string IntToRoman(int num)
{
string[] ch = new string[] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
int[] value = new int[] { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
string ans = "";
for (int i=0;num!=0;++i)
{
while (num >= value[i])
{
num -= value[i];
ans += ch[i];
}
}
return ans;
}
}