Nuestro grupo de especialistas despúes de ciertos días de investigación y recopilación de de información, hemos dado con la respuesta, esperamos que todo este artículo sea de gran utilidad para tu plan.
Ejemplo 1: convertidor de números romanos
// Visit=> https://duniya-roman-numeral-converter.netlify.app/const convertToRoman = num =>const numbers =[1000,900,500,400,100,90,50,40,10,9,5,4,1]const roman =['M','CM','D','CD','C','XC','L','XL','X','IX','V','IV','I']
let romanNumeral =''// While num is not equal to 0, keep iterating with the valuewhile(num !==0)// Find from the numbers array the match for the current numberconst index = numbers.findIndex(nums => num >= nums)// Keeping pushing the roman value to romanNumeral// Cause the found number from numbers matches the index of its// Corresponding roman below
romanNumeral += roman[index]// Set num to a new value by Substracting the used number from it
num -= numbers[index]return romanNumeral
convertToRoman(3999);// With love @kouqhar
Ejemplo 2: números romanos a números
//Java Implementation of Roman To NumberpublicclassRomanToNumberpublicstaticintdeclareIntOfChar(char c)int val=0;switch(c)case'I':
val=1;break;case'V':
val=5;break;case'X':
val=10;break;case'L':
val=50;break;case'C':
val=100;break;case'D':
val=500;break;case'M':
val=1000;break;default:
val=-1;break;return val;publicstaticvoidmain(String[] args)String s ="XCV";int sum =0,c1,c2;for(int i=0;i<s.length();i++)
c1=declareIntOfChar(s.charAt(i));if(i+1<s.length())
c2=declareIntOfChar(s.charAt(i+1));if(c1<c2)
sum = sum + c2 - c1;
i++;else
sum = sum + c1;else
sum = sum + c1;System.out.print(s +" = "+ sum);
Ejemplo 3: convertir a código numérico romano
class py_solution:
def int_to_Roman(self, num):
val =[1000,900,500,400,100,90,50,40,10,9,5,4,1]
syb =["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
roman_num =''
i =0while num >0:for _ in range(num // val[i]):
roman_num += syb[i]
num -= val[i]
i +=1return roman_num
print(py_solution().int_to_Roman(1))print(py_solution().int_to_Roman(4000))
Ejemplo 4: incrustación de tabla de conversión de números romanos
function convertToRoman()
let arabic = document.getElementById('arabicNumeral').value;// input value
let roman ='';// variable that will hold the result
Ejemplo 5: incrustación de tabla de conversión de números romanos
if(/^(0|[1-9]d*)$/.test(arabic))// Regular expression testsif(arabic ==0)// for decimal points and negative
outputField.innerHTML ="Nulla";// signselseif(arabic !=0)for(let i =0; i < arabicArray.length; i++)while(arabicArray[i]<= arabic)
roman += romanArray[i];
arabic -= arabicArray[i];
outputField.innerHTML = roman;else
outputField.innerHTML ="Please enter non negative integers only. No decimal points.";
Comentarios y puntuaciones
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)