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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int toint(char s){
  if(s=='I') return 1;
  if(s=='V') return 5;
  if(s=='X') return 10;
  if(s=='L') return 50;
  if(s=='C') return 100;
  if(s=='D') return 500;
  if(s=='M') return 1000;
}
int main(void){
  string line;
  while(cin>>line){
    int ret=0;
    REP(i,line.size()-1){
      if(toint(line[i+1])-toint(line[i])>0){
        ret -= toint(line[i]);
      }else{
        ret += toint(line[i]);
      }
    }
    ret += toint(line[line.size()-1]);
    cout<<ret<<endl;
  }    
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    string figure;

    while(cin >> figure) {
        int result = 0;
        char prev = '?';

        for(int i = 0; i < figure.length(); i++) {
            switch(figure[i]) {
                case 'M':
                    result += 1000;
                    if (prev == 'C')    result -= 200;
                    break;
                case 'D':
                    result += 500;
                    if (prev == 'C')    result -= 200;
                    break;
                case 'C':
                    result += 100;
                    if (prev == 'X')    result -= 20;
                    break;
                case 'L':
                    result += 50;
                    if (prev == 'X')    result -= 20;
                    break;
                case 'X':
                    result += 10;
                    if (prev == 'I')    result -= 2;
                    break;
                case 'V':
                    result += 5;
                    if (prev == 'I')    result -= 2;
                    break;
                case 'I':
                    result += 1;
                    break;
            }
            prev = figure[i];
        }

        cout << result << endl;
    }
     
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>
#include <utility>
#include <numeric>

typedef long long Int; 
#pragma warning(disable : 4996)
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define REPS(a,i,n) for(int i = a ; i < n ; ++i)
using namespace std;

map<char, int> tile;

int main(){
	tile['I'] = 1;
	tile['V'] = 5;
	tile['X'] = 10;
	tile['L'] = 50;
	tile['C'] = 100;
	tile['D'] = 500;
	tile['M'] = 1000;

	string a;
	while (cin >> a){
		Int ans(0);

		char before = 'I';
		for (auto i = a.rbegin(); i != a.rend();++i){
			if (tile[before] > tile[*i]){
				ans -= tile[*i];
			}
			else{
				ans += tile[*i];
			}
			before = *i;
		}

		cout << ans << endl;
	}
	return 0;
}