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)
	}
}

C++: #include<iostream>
#include<map>
#include<string>
using namespace std;
typedef pair<int,int> P;
int main(){
  map<char,int> tmp;
  tmp['I']=1,tmp['V']=5,tmp['X']=10,tmp['L']=50,tmp['C']=100,tmp['D']=500,tmp['M']=1000;
  string str;
  while(cin >> str){
    int ans = 0,i=0;
    while(1){
      if(i == str.size() - 1) {
	ans += tmp[str[str.size()-1]];
	break;
      }
      if(tmp[str[i]] < tmp[str[i+1]]) ans -= tmp[str[i]];
      else ans += tmp[str[i]];
      i++;
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <map>

using namespace std;

void solve()
{
	map<char, int> Map;
	Map['I'] = 1;
	Map['V'] = 5;
	Map['X'] = 10;
	Map['L'] = 50;
	Map['C'] = 100;
	Map['D'] = 500;
	Map['M'] = 1000;
	string s;
	while(cin >> s)
	{
		int sum = 0;
		int n = s.size();
		for(int i = 0; i < n; ++i)
		{
			if(i < n - 1 && Map[s[i]] < Map[s[i + 1]])
			{
				sum += Map[s[i + 1]] - Map[s[i]];
				++i;
			}
			else
			{
				sum += Map[s[i]];
			}
		}
		cout << sum << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<cstdio>
#include<string>
using namespace std;

int main()
{
    string str;
    while(cin>>str,!cin.eof()){
        int block[str.length()],num=0;
        for(int i=0;i<str.length();i++){
            switch(str[i]){
                case 'M' :
                    block[i]=1000;
                    break;
                case 'D' :
                    block[i]=500;
                    break;
                case 'C' :
                    block[i]=100;
                    break;
                case 'L' :
                    block[i]=50;
                    break;
                case 'X' :
                    block[i]=10;
                    break;
                case 'V' :
                    block[i]=5;
                    break;
                case 'I' :
                    block[i]=1;
                    break;
            }
        }
        for(int i=0;i<str.length();i++){
            if(block[i]<block[i+1] && i!=str.length()-1){
                num += block[i+1]-block[i];
                i++;
            }
            else{
                num += block[i];
            }
        }
        cout<<num<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;

int main()
{
	string str;
	int ary[100];
	int ans = 0;

	while (cin >> str)
	{
		ans = 0;

		for (int i = 0; i < str.size(); i++)
		{
			if (str[i] == 'I') ary[i] = 1;
			if (str[i] == 'V') ary[i] = 5;
			if (str[i] == 'X') ary[i] = 10;
			if (str[i] == 'L') ary[i] = 50;
			if (str[i] == 'C') ary[i] = 100;
			if (str[i] == 'D') ary[i] = 500;
			if (str[i] == 'M') ary[i] = 1000;
		}

		for (int i = 0; i < str.size() - 1; i++)
		{
			if (ary[i] < ary[i + 1]) ans -= ary[i];
			else					 ans += ary[i];
		}
		ans += ary[str.size() - 1];
		cout << ans << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main(){
	map<char, int> m;
	m['I'] = 1;m['V'] = 5;m['X'] = 10;m['L'] = 50;
	m['C'] = 100;m['D'] = 500;m['M'] = 1000;
	string s;
	while(cin >> s){
		int i = 0, ans = 0;
		while(i < s.size()){
			char c = s[i];
			int t = 0;
			for(i;c == s[i] && i < s.size()-1;i++)t += m[c];
			if(m[c] < m[s[i]])ans -= t;
			else ans += t;
			if(i == s.size()-1)ans += m[s[i++]];
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;

int num(char c) {
	switch (c) {
		case 'I': return 1;
		case 'V': return 5;
		case 'X': return 10;
		case 'L': return 50;
		case 'C': return 100;
		case 'D': return 500;
		case 'M': return 1000;
	}
	return 0;
}

int main() {
	string s;
	while (cin >> s) {
		int n = 0;
		for (int i = 0; i < s.size(); i++) {
			int a = num(s[i]);
			int b = i+1 < s.size() ? num(s[i+1]) : 0;
			if (a >= b)
				n += a;
			else
				n += b-a, i++;
		}
		cout << n << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main() {
	char str[128]="";
	vector<int> r;
	while (scanf("%s",str) != EOF)
	{
		int i=-1;
		int pn=0,n=0,s=0;
		do
		{
			i++;
			switch (str[i]){
				case 'M':
					n=1000;
					break;
				case 'D':
					n=500;
					break;
				case 'C':
					n=100;
					break;
				case 'L':
					n=50;
					break;
				case 'X':
					n=10;
					break;
				case 'V':
					n=5;
					break;
				case 'I':
					n=1;
					break;
				default:
					n=0;
					break;
			}
			if (pn<n && pn!=0)
			{
				s+=n-pn;
				pn=0;
			} else {
				s+=pn;
				pn=n;
			}
		} while (str[i] != 0);
		r.push_back(s);
	}
	for (int i=0; i<r.size(); i++)
	{
		cout << r[i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){

	map <char, int> mp;
	mp['I'] = 1;
	mp['V'] = 5;
	mp['X'] = 10;
	mp['L'] = 50;
	mp['C'] = 100;
	mp['D'] = 500;
	mp['M'] = 1000;


	string p;

	while (cin >> p){
		int p_buf = 0;
		int ans[3] = { 0, 0, 0 };

		for (int i = 0; i < p.size(); i++){
			if (mp[p[i]] > p_buf){
				ans[2] = mp[p[i]] - p_buf + ans[0];
			}
			else{
				ans[2] = mp[p[i]] + ans[1];
			}
			ans[0] = ans[1];
			ans[1] = ans[2];
			p_buf = mp[p[i]];
			//cout << ans[2] << ",";
		}
		//cout << endl;

		cout << ans[2] << endl;

	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  map<char,int>m;
  m['I']=1;
   m['V']=5;
    m['X']=10;
     m['L']=50;
      m['C']=100;
       m['D']=500;
        m['M']=1000;
  string s;
  while(cin>>s){
    reverse(s.begin(),s.end());
    int p=0;
    p+=m[s[0]];
    for(int i=1;i<s.size();i++)
      if(m[s[i]]<m[s[i-1]])p-=m[s[i]];
        else p+=m[s[i]];
    cout<<p<<endl;
  }
}