Roman numerals are represented by seven different symbols: I, V, X, L, C, D, M
/*
* Roman numerals are represented by seven different symbols: I, V, X, L, C, D, M
* Symbol Value
* I 1
* V 5
* X 10
* L 50
* C 100
* D 500
* M 1000
*
* Input : 3
* Output : "III"
*
* Input : 4
* Output : "IV"
*
* Input : 58
* Output : "LVIII"
*
* Input : 1994
* Output : "MCMXCIV"
*/
public string LeetCode_12(int num)
{
string ans = "";
string[] s = { "I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M" };
int[] gain = { 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 };
int c = gain.Length-1;
//
while (num != 0)
{
if(num/gain[c] >= 1)
{
num = num - gain[c];
ans += s[c];
}
else
{
c--;
}
}
return ans;
}