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;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

int ans;
string str;


int main() {
	while ( ( cin >> str ) ) {
		ans = 0;
		for ( int i = 0; i < str.size(); i++ ) {
			if ( str[ i ] == 'M' ) {
				if ( ans % 1000 ) {
					ans += 800;
				}
				else {
					ans += 1000;
				}
			}
			else if ( str[ i ] == 'D' ) {
				if ( ans % 500 ) {
					ans += 300;
				}
				else {
					ans += 500;
				}
			}
			else if ( str[ i ] == 'C' ) {
				if ( ans % 100 ) {
					ans += 80;
				}
				else {
					ans += 100;
				}
			}
			else if ( str[ i ] == 'L' ) {
				if ( ans % 50 ) {
					ans += 30;
				}
				else {
					ans += 50;
				}
			}
			else if ( str[ i ] == 'X' ) {
				if ( ans % 10 ) {
					ans += 8;
				}
				else {
					ans += 10;
				}
			}
			else if ( str[ i ] == 'V' ) {
				if ( ans % 5 ) {
					ans += 3;
				}
				else {
					ans += 5;
				}
			}
			else {
				ans++;
			}
		}
		printf( "%d\n", ans );
	}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	string s;
	while (cin >> s){
		vector<int> num;
		REP(i, s.length()){
			int a;
			if (s[i] == 'I')
				a = 1;
			if (s[i] == 'V')
				a = 5;
			if (s[i] == 'X')
				a = 10;
			if (s[i] == 'L')
				a = 50;
			if (s[i] == 'C')
				a = 100;
			if (s[i] == 'D')
				a = 500;
			if (s[i] == 'M')
				a = 1000;
			num.push_back(a);
		}
		int ans = 0;
		REP(i,num.size()){
			
			if (i==num.size()-1||num[i] >= num[i + 1]){
				ans += num[i];
			}
			else{
				ans += num[i + 1] - num[i];
				i++;
			}
		}
		cout << ans << endl;
	}
}

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

C++: #include <vector>
#include <iostream>
#include <map>
using namespace std;
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	map<char,int> t;
	t['I']=1, t['X']=10, t['V'] = 5;
	t['L'] = 50 , t['C'] = 100 , t['M'] = 1000 , t['D'] = 500;
	string s;
	while(cin >> s){
		int ret = 0;
		ret += t[s[0]];
		rep(i,s.length()-1){
			if(t[s[i+1]] > t[s[i]])ret -= 2*t[s[i]];
			ret += t[s[i+1]];
		}
		cout << ret << endl;
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }



int main()
{
	string str;
	map<char, int> p;

	p.insert(map<char, int>::value_type('I', 1));
	p.insert(map<char, int>::value_type('V', 5));
	p.insert(map<char, int>::value_type('X', 10));
	p.insert(map<char, int>::value_type('L', 50));
	p.insert(map<char, int>::value_type('C', 100));
	p.insert(map<char, int>::value_type('D', 500));
	p.insert(map<char, int>::value_type('M', 1000));


	while(cin >> str)
	{
		int len = str.size();
		vint num(len);

		rep(i, len)
			num[i] = p[str[i]];

		int res = 0;
		rep(i, len-1)
		{
			if(num[i+1] <= num[i])
			{
				res += num[i];
				if(i + 2 == len) res += num[len-1];
			}
			else
			{
				res += num[i+1] - num[i];
				i++;
			}
		}

		cout << res << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
map<char, int> dict;
int main(){
    dict['I'] = 1;
    dict['V'] = 5;
    dict['X'] = 10;
    dict['L'] = 50;
    dict['C'] = 100;
    dict['D'] = 500;
    dict['M'] = 1000;
    string str;
	    
    while(cin >> str){
	int res = 0;
	char now = str[0];
	int cnt = 1;
	for(int i = 1;i < str.size();i++){
	    if(str[i] == now)cnt++;
	    else{
		if(dict[str[i]] > dict[now])res -= cnt * dict[now];
		else res += cnt * dict[now];
		now = str[i];
		cnt = 1;
	    }
	}
	res += cnt * dict[now];
	cout << res << endl;
    }
    return 0;
}