Go: package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	dict := make(map[string]int)
	dict[" "] = 0
	dict["I"] = 1
	dict["V"] = 5
	dict["X"] = 10
	dict["L"] = 50
	dict["C"] = 100
	dict["D"] = 500
	dict["M"] = 1000
	for scanner.Scan() {
		line := strings.Split(scanner.Text(), "")
		line = append(line, " ")
		sum := 0
		for i := 0; i < len(line)-1; i++ {
			if dict[line[i]] < dict[line[i+1]] {
				sum -= dict[line[i]]
			} else {
				sum += dict[line[i]]
			}
		}
		fmt.Println(sum)
	}
}

Python: import sys
def todec(s):
    roman_dic = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
    ret, prev = 0, 0
    for i in reversed(s):
        d = roman_dic[i]
        if d < prev:
            ret -= d
        else:
            ret += d
        prev = d
    return ret

A = sys.stdin.read().split()
for a in A:
    print(todec(a))

Python: 
def Roman_numerals(x):
	if x=='I':
		return 1
	elif x=='V':
		return 5
	elif x=='X':
		return 10
	elif x=='L':
		return 50
	elif x=='C':
		return 100
	elif x=='D':
		return 500
	elif x=='M':
		return 1000




while True:
	try:
		s=0
		string=input()
		for i in range(len(string)):
			tmp_now =Roman_numerals(string[i:i+1])
			tmp_next=Roman_numerals(string[i+1:i+2])
			if (tmp_now==1 and tmp_next==5):
				s+=-1
			elif (tmp_now==1 and tmp_next==10):
				s+=-1
			elif (tmp_now==10 and tmp_next==50):
				s+=-10
			elif (tmp_now==10 and tmp_next==100):
				s+=-10
			elif (tmp_now==100 and tmp_next==500):
				s+=-100
			else:
				s+=tmp_now
		print(s)

	except EOFError:
		break

Python: figures = ["M", "D", "C", "L", "X", "V", "I"]
hoge = {0: 1000, 1: 500, 2: 100, 3: 50, 4: 10, 5: 5, 6: 1}

while True:
    try:
        st = input()
    except:
        break
    idx = figures.index(st[0])
    res = [hoge[idx]]
    pretoken = st[0]
    for i, s in enumerate(st[1:]):
        idx = figures.index(s)
        preidx = figures.index(pretoken)
        if idx < preidx:
            res[i] = -1 * res[i]
        res.append(hoge[idx])
        pretoken = s
    print(sum(res))

Python: # Aizu Problem 0039: Roman Figure
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def roman_to_decimal(r):
    n = 0
    while len(r) > 0 and r[0] == "M":
        n += 1000
        r = r[1:]
    if len(r) == 0:
        return n
    if r[:2] == "CM":
        n += 900
        r = r[2:]
    if len(r) == 0:
        return n
    if r[0] == "D":
        n += 500
        r = r[1:]
    if len(r) == 0:
        return n
    if r[:2] == "CD":
        n += 400
        r = r[2:]
    if len(r) == 0:
        return n
    while len(r) > 0 and r[0] == "C":
        n += 100
        r = r[1:]
    if len(r) == 0:
        return n
    if r[:2] == "XC":
        n += 90
        r = r[2:]
    if len(r) == 0:
        return n
    if r[0] == "L":
        n += 50
        r = r[1:]
    if len(r) == 0:
        return n
    if r[:2] == "XL":
        n += 40
        r = r[2:]
    if len(r) == 0:
        return n
    while len(r) > 0 and r[0] == "X":
        n += 10
        r = r[1:]
        if len(r) == 0:
            return n
    if r[:2] == "IX":
        n += 9
    elif r[:2] == "IV":
        n += 4
    else:
        if r[0] == "V":
            n += 5
            r = r[1:]
        while len(r) > 0 and r[0] == "I":
            n += 1
            r = r[1:]
            if len(r) == 0:
                return n
    return n

for line in sys.stdin:
    print(roman_to_decimal(line.strip()))

Python: import sys

roman = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}


def check(i, y):
  if i == y:
    return True
  elif i == 'I' and y == 'V':
    return True
  elif i == 'V' and (y == 'I' or y == 'X'):
    return True
  elif i == 'X' and (y == 'V' or y == 'L'):
    return True
  elif i == 'L' and (y == 'X' or y == 'C'):
    return True
  elif i == 'C' and (y == 'L' or y == 'D'):
    return True
  elif i == 'D' and (y == 'C' or y == 'M'):
    return True
  elif i == 'M' and y == 'D':
    return True
  else:
    return False


def solve(r):
  if len(r) == 1:
    return roman[r[0]]
  else:
    maxRoman = 0
    for i in range(len(r) - 1):
      if roman[r[i]] < roman[r[i + 1]]:
        maxRoman = i + 1
      else:
        break
    ans = roman[r[maxRoman]]
    for sub in range(maxRoman - 1, -1, -1):
      ans -= roman[r[sub]]
    for add in range(maxRoman + 1, len(r)):
      if add < len(r) - 1 and not check(r[add - 1], r[add]):
        r = r[add:]
        return ans + solve(r)
      ans += roman[r[add]]
  return ans


for line in sys.stdin:
  try:
    line = line.replace('\n', '')
    print(solve(line))
  except:
    break

Python: # AOJ 0039 Roman Figure
# Python3 2018.6.15 bal4u

roman = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M': 1000}

while True:
	try:
		p = list(input())
	except EOFError:
		break
	ans = i = 0
	while i < len(p):
		if i+1 < len(p) and roman[p[i]] < roman[p[i+1]]:
			ans += roman[p[i+1]] - roman[p[i]]
			i += 1
		else: ans += roman[p[i]]
		i += 1
	print(ans)

Python: def translation(string):
    roman = {'I': 1, 'V': 5, 'X': 10, 'L': 50,
             'C': 100, 'D': 500, 'M': 1000 }
    ans = 0
    for i in range(len(string)):
        if i == len(string)-1 or \
            roman[string[i]] >= roman[string[i+1]]:
            ans += roman[string[i]] * 1
        else:
            ans += roman[string[i]] * -1
    return ans

while True:
    try: start = input()
    except: break
    
    ans = translation(start)
    print(ans)

Python: nums={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}
while True:
    try:
        s=input()
    except:
        break
    ans=nums[s[0]]
    for i in range(1,len(s)):
        if nums[s[i-1]]<nums[s[i]]:
            ans-=2*nums[s[i-1]]
        ans+=nums[s[i]]
    print(ans)

Python: t = {"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}

while 1:
    try:
        s = [t[i] for i in input()]
    except:
        break
    i = 0
    while i < len(s) - 1:
        if s[i] < s[i + 1]:
            s[i + 1] = s[i + 1] - s[i]
            s.pop(i)
        i += 1
    print(sum(s))

Python: import sys

h = {'I' : 1, 'V' : 5, 'X' : 10, 'L' : 50, 'C' : 100, 'D' : 500, 'M' : 1000, 'E' : 0}

for line in sys.stdin:
	line = line.rstrip()
	line += 'E'
	ans = 0
	i = 0
	while i < len(line) - 1:
		if h[line[i]] >= h[line[i+1]]:
			ans += h[line[i]]
		else:
			ans += h[line[i+1]] - h[line[i]]
			i += 1
		i += 1
	print(ans)

Python: import sys
r_d={"I":1,"V":5,"X":10,"L":50,"C":100,"D":500,"M":1000}
res=[]
for s in sys.stdin:
    l=[r_d[i] for i in s.strip()]
    m=[l[i] if l[i]>=l[i+1] else -l[i] for i in range(len(l)-1)]
    m.extend([l[-1]])
    res.extend([sum(m)])
[print(i) for i in res]

Python: num = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}

while True:
    try:
        S = input()
    except EOFError:
        break
    ans = 0
    for i in range(0,len(S) - 1):
        if num [S [i]] < num [S [i + 1]]:
            ans -= num [S [i]]
        else:
            ans += num [S [i]]
    ans += num [S [-1]]
    print(ans)