1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-19 14:16:55 +02:00
CodeWars/6kyu/roman_numerals_encoder/solution.cs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

38 lines
696 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
public class RomanConvert
{
private static Dictionary<int, string> values = new Dictionary<int, string>() {
{ 1, "I" },
{ 4, "IV" },
{ 5, "V" },
{ 9, "IX" },
{ 10, "X" },
{ 40, "XL" },
{ 50, "L" },
{ 90, "XC" },
{ 100, "C" },
{ 400, "CD" },
{ 500, "D" },
{ 900, "CM" },
{ 1000, "M" }
};
public static string Solution(int n)
{
var result = "";
var keys = values.Keys.Reverse();
foreach (var key in keys) {
while (n / key > 0) {
result += values[key];
n -= key;
}
}
return result;
}
}