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
Conversão de um numeral romano para um int. Os símbolos são I=1, V=5, X=10, L=50, C=100, D=500, M=1000. Geralmente você soma, mas quando um símbolo menor fica antes de um maior, subtraia-o: IV é 4, IX é 9, MCMXCIV é 1994. Escanear da direita para a esquerda facilita a regra de subtração — subtraia qualquer símbolo menor que o que está à sua direita.
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. · Complete romanToInt(String s) convertendo um numeral romano para um int. Um símbolo menor antes de um maior subtrai, então IV é 4 e MCMXCIV é 1994. Assuma entrada válida.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.