Roman numerals · Números romanos
Roman numerals
Convert a Roman numeral to an int. The symbols are I=1, V=5, X=10, L=50, C=100, D=500, M=1000. Usually you add, but when a smaller symbol sits before a larger one you subtract it: IV is 4, IX is 9, MCMXCIV is 1994. Scanning from right to left makes the subtract rule easy — subtract any symbol smaller than the one to its right.
Números romanos
Convierte un número romano a int. Los símbolos son I=1, V=5, X=10, L=50, C=100, D=500, M=1000. Usualmente se suman, pero cuando un símbolo más pequeño está antes de uno más grande se resta: IV es 4, IX es 9, MCMXCIV es 1994. Escanear de derecha a izquierda facilita la regla de resta — se resta cualquier símbolo que sea menor que el que tiene a su derecha.
Complete romanToInt(String s) converting a Roman numeral to an int. A smaller symbol before a larger one is subtracted, so IV is 4 and MCMXCIV is 1994. Assume valid input. · Completa romanToInt(String s) para convertir un numeral romano a un int. Un símbolo menor precediendo a uno mayor se resta, por lo que IV es 4 y MCMXCIV es 1994. Asume entrada válida.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.