#No me deja ver la página inicie sesión y
1 messages · Page 1 of 1 (latest)
abro un hilo para no hacer spams y la coloco acá
using System;
public class RomanConvert
{
public static string Solution(int n)
{
string[] letters = {"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"};
int[] values = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
int index = letters.Length - 1;
string ans = "";
while(n > 0)
{
int quotient = (int)Math.Floor((double)(n / values[index]));
for(int i = 0; i < quotient; ++i)ans += letters[index];
n -= values[index] * quotient;
index--;
}
return ans;
}
}
Es C# pero la lógica creo que se entiende para hacer en otro lenguaje, igual si algo me preguntas
Este método te convierte cualquier número entre 1 y 3999 a Romano, lo puedes usar para no hacerlos a mano