-
Notifications
You must be signed in to change notification settings - Fork 0
/
RomanNumeral.cs
39 lines (36 loc) · 975 Bytes
/
RomanNumeral.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections.Generic;
namespace KataRomanNumerals
{
public class RomanNumeral
{
private readonly Dictionary<int, string> _arabic2Roman = new Dictionary<int, string>
{
{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"}
};
public string ToRoman(int arabicNumeral)
{
var romanNumeral = string.Empty;
foreach (var arabicFigure in _arabic2Roman.Keys)
{
while (arabicNumeral >= arabicFigure)
{
romanNumeral += _arabic2Roman[arabicFigure];
arabicNumeral -= arabicFigure;
}
}
return romanNumeral;
}
}
}