Created
March 26, 2016 21:10
-
-
Save pbassut/ed4f0e981e05c09c9cc7 to your computer and use it in GitHub Desktop.
UNFINISHED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import math | |
from collections import deque | |
# Auto-generated code below aims at helping you parse | |
# the standard input according to the problem statement. | |
table = { | |
'I': 1, | |
'V': 5, | |
'X': 10, | |
'L': 50, | |
'C': 100, | |
'D': 500, | |
'M': 1000 | |
} | |
atable = { | |
1: 'I', | |
5: 'V', | |
10: 'X', | |
50: 'L', | |
100: 'C', | |
500: 'D', | |
1000: 'M' | |
} | |
convert = lambda x: table[x] | |
aconvert = lambda x: atable[x] | |
def find_max_index(roman): | |
current = 0 | |
for index, letter in enumerate(list(roman)[1:]): | |
if convert(letter) > convert(roman[current]): | |
current = index + 1 | |
return current | |
def process(roman): | |
pivot = find_max_index(roman) | |
return sum(map(convert, roman[pivot:])) - sum(map(convert, roman[:pivot])) | |
def encode(i): | |
digits = deque() | |
for v in sorted(atable.keys(), reverse=True): | |
while i >= v: | |
i -= v | |
digits.append(aconvert(v)) | |
return ''.join(digits) | |
rom_1 = raw_input() | |
rom_2 = raw_input() | |
print encode(process(rom_1) + process(rom_2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment