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 <bits/stdc++.h>
using namespace std;

bool match( char ch, const string& p ) {
	for( auto a: p ) {
		if( a == ch ) { return true; }
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio( false );

	string s;
	while( cin >> s ) {
		int n = (int)s.size();
		int result = 0;

		for( int i = n-1; i >= 0; --i ) {
			if( s[i] == 'I' ) {
				result += i < n-1 && s[i+1] != 'I' ? -1 : 1;
			}
			else if( s[i] == 'V' ) {
				result += i < n-1 && match( s[i+1], "XLCDM" ) ? -5 : 5;
			}
			else if( s[i] == 'X' ) {
				result += i < n-1 && match( s[i+1], "LCDM" ) ? -10 : 10;
			}
			else if( s[i] == 'L' ) {
				result += i < n-1 && match( s[i+1], "CDM" ) ? -50 : 50;
			}
			else if( s[i] == 'C' ) {
				result += i < n-1 && match( s[i+1], "DM" ) ? -100 : 100;
			}
			else if( s[i] == 'D' ) {
				result += i < n-1 && match( s[i+1], "M" ) ? -500 : 500;
			}
			else if( s[i] == 'M' ) {
				result += 1000;
			}
		}

		cout << result << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

char u[] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
int v[] =  {1, 5, 10, 50, 100, 500, 1000};

int value_of (char c) {
  rep (i, 7) {
    if (c == u[i]) return v[i];
  }
}

int max_u(string s) {
  int ac = -1;
  int r = -1;
  rep (i, s.size()) {
    int vl = value_of(s[i]);
    if (ac < vl) {
      ac = vl;
      r = i;
    }
  }
  return r;
}

int read(string s) {
  if (s == "") return 0;
  int idx = max_u(s);
  int x = value_of(s[idx]);
  string t1 = s.substr(0, idx);
  string t2 = s.substr(idx + 1, s.size() - idx - 1);
  return -read(t1) + x + read(t2);
}

int main() {

  for (string s; cin >> s, cin; ) {
    cout << read(s) << endl;
  }

  return 0;
}

C++: #include<cstdio>
#include<algorithm>

using namespace std;

char date[105];
int ndate[105];

int main()
{
	while(scanf("%s",date)!=EOF)
	{
		for(int i=0;i<105;i++)
		{
			if(date[i]=='I')ndate[i]=1;
			if(date[i]=='V')ndate[i]=5;
			if(date[i]=='X')ndate[i]=10;
			if(date[i]=='L')ndate[i]=50;
			if(date[i]=='C')ndate[i]=100;
			if(date[i]=='D')ndate[i]=500;
			if(date[i]=='M')ndate[i]=1000;
		}
		int answer=0;
		for(int i=104;i>0;i--)
		{
			if(ndate[i]>ndate[i-1])
			{
				answer-=ndate[i-1];
			}
			else if(ndate[i]==0)
			{
				answer+=ndate[i-1];
			}
			else
			{
				answer+=ndate[i-1];
			}
		}
		printf("%d\n",answer);
		fill(date,date+105,'\0');
		fill(ndate,ndate+105,0);
	}
}

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

int main(){
    string ss;
    int num[128];
    num['M'] = 1000;
    num['D'] = 500;
    num['C'] = 100;
    num['L'] = 50;
    num['X'] = 10;
    num['V'] = 5;
    num['I'] = 1;
    while( cin >> ss ){
        int answer = 0;
        string::iterator it = ss.begin();
        while( it != ss.end() ){
            if( it+1 == ss.end() || num[ *it ] >= num[ *(it+1) ] ){
                answer += num[ *it ];
            }else{
                answer += num[ *(it+1) ] - num[ *it ];
                it++;
            }
            it++;
        }
        cout << answer << endl;
    }
    return 0;
}

C++: 
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  char s[10000];
  while(scanf("%s",s)!=EOF){
    int n=strlen(s);
    vi a(n);
    rep(i,n)
      if(s[i]=='I')a[i]=1;
      else if(s[i]=='V')a[i]=5;
      else if(s[i]=='X')a[i]=10;
      else if(s[i]=='L')a[i]=50;
      else if(s[i]=='C')a[i]=100;
      else if(s[i]=='D')a[i]=500;
      else if(s[i]=='M')a[i]=1000;
    int ans=0;
    rep(i,n-1)
      if(a[i]>=a[i+1])ans+=a[i];
      else ans-=a[i];
    cout<<ans+a[n-1]<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		int b[2][100000]={0};bool bb[2][100000]={0};
		int a[100],sum=0;
		for(int i=0;i<s.size();i++){
			int t;
			if(s[i]=='I')t=1;
			if(s[i]=='V')t=5;
			if(s[i]=='X')t=10;
			if(s[i]=='L')t=50;
			if(s[i]=='C')t=100;
			if(s[i]=='D')t=500;
			if(s[i]=='M')t=1000;
			a[i]=t;
			if(i&&a[i]!=a[i-1]&&b[0][a[i]])b[1][t]++;
			else b[0][t]++;
		}
		for(int i=s.size()-1;i>=0;i--){
			if(sum<a[i]){
				if(i!=s.size()-1&&a[i]!=a[i+1]&&bb[0][a[i]]){
					sum-=b[1][a[i]]*a[i];
				    i-=b[1][a[i]]-1;
				}
				else{sum+=b[0][a[i]]*a[i];
				i-=b[0][a[i]]-1;bb[0][a[i]]=1;}
			}		
			else{
				sum-=b[0][a[i]]*a[i];
				    i-=b[0][a[i]]-1;
				    bb[0][a[i]]=1;
			}
		}
		cout<<sum<<endl;
	}
}