#!/usr/bin/env python3
def romanToInt(s):
dict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
sum = 0
y = 0 # 比較用の変数
for i in s[::-1]: # sは入力された文字列のこと
if y <= dict[i] or y == 0:
sum += dict[i]
y = dict[i]
else:
sum -= dict[i]
return sum
if __name__ == '__main__':
print(romanToInt('MC'))
print(romanToInt('IV'))
IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwoKZGVmIHJvbWFuVG9JbnQocyk6CiAgICBkaWN0ID0geydJJzogMSwgJ1YnOiA1LCAnWCc6IDEwLCAnTCc6IDUwLCAnQyc6IDEwMCwgJ0QnOiA1MDAsICdNJzogMTAwMH0KCiAgICBzdW0gPSAwCiAgICB5ID0gMCAjIOavlOi8g+eUqOOBruWkieaVsAogICAgZm9yIGkgaW4gc1s6Oi0xXTogIyBz44Gv5YWl5Yqb44GV44KM44Gf5paH5a2X5YiX44Gu44GT44GoCiAgICAgICAgaWYgeSA8PSBkaWN0W2ldIG9yIHkgPT0gMDoKICAgICAgICAgICAgc3VtICs9IGRpY3RbaV0KICAgICAgICAgICAgeSA9IGRpY3RbaV0KICAgICAgICBlbHNlOgogICAgICAgICAgICBzdW0gLT0gZGljdFtpXQogICAgcmV0dXJuIHN1bQoKaWYgX19uYW1lX18gPT0gJ19fbWFpbl9fJzoKICAgIHByaW50KHJvbWFuVG9JbnQoJ01DJykpCiAgICBwcmludChyb21hblRvSW50KCdJVicpKQo=