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 <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int roman_to_n(const string& s)
{
	static const int num[] = { 1, 5, 10, 50, 100, 500, 1000 };
	static const char* roman = "IVXLCDM";

	vector<int> digits(s.size());
	for (int i = 0; i < s.size(); ++i)
		digits[i] = num[strchr(roman, s[i]) - roman];

	int res = accumulate(digits.begin(), digits.end(), 0);
	for (int i = 0; i < digits.size() - 1; ++i)
		if (digits[i] < digits[i + 1])
			res -= 2 * digits[i];
	return res;
}
string to_roman(int n)
{
	static const char* roman[][10] = {
		{ "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" }, 
		{ "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" },
		{ "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
		{ "", "M", "MM", "MMM", "MMMM", "MMMMM" },
	};

	stringstream res;
	for (int i = 3, j = 1000; i >= 0; --i, j /= 10)
		res << roman[i][(n / j) % 10];
	return res.str();
}
int main()
{
	string s;
	while (cin >> s)
		cout << roman_to_n(s) << endl;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<map>
using namespace std;
int main(){
	string str;
	map<char,int> A;
	A['I'] = 1;
	A['V'] = 5;
	A['X'] = 10;
	A['L'] = 50;
	A['C'] = 100;
	A['D'] = 500;
	A['M'] = 1000;
	A['E'] = -1;
	while(cin >> str){
	    int ans = 0;
	    str += "E";
        for(int i = 0; str[i] != 'E'; i++){
            if(A[str[i]] < A[str[i+1]]){
                ans -= A[str[i]];
            }
            else{
                ans += A[str[i]];
            }
        }
        cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;


int main()
{
	char* ara = "IVXLCDM";
	int num[] = { 1, 5, 10, 50, 100, 500, 1000 };

	char buf[101];
	while (scanf("%s\n", buf) != EOF)
	{
		int len = strlen(buf);
		int n[100];
		for (int i = 0; i < len; ++i)
		{
			for (int j = 0; j < 7; ++j)
			{
				if (buf[i] == ara[j])
				{
					n[i] = num[j];
					break;
				}
			}
		}
		for (int i = 0; i < len-1; ++i)
			n[i] *= n[i] < n[i+1] ? -1 : 1;

		int res = 0;
		for (int i = 0; i < len; ++i)
			res += n[i];

		printf("%d\n", res);
	}

	return 0;
}

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

C++: #include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int toNum(char ch){
	if( ch=='I' ) return 1;
	if( ch=='V' ) return 5;
	if( ch=='X' ) return 10;
	if( ch=='L' ) return 50;
	if( ch=='C' ) return 100;
	if( ch=='D' ) return 500;
	if( ch=='M' ) return 1000;
	return 0;
}

int main(){
	string str;
	while( cin>>str ){
		vector<int> s;
		int sum = 0;

		s.clear();
		rep(i,str.size()) s.pb( toNum(str[i]) );

		while( s.size()>0 ){
			int maxi = -1;
			int pos = -1;
			rep(i,s.size()){
				if( s[i]>=maxi ){
					maxi = s[i];
					pos = i;
				}
			}
			if( pos!=0 && s[pos-1]<s[pos] ){
				sum += s[pos]-s[pos-1];
				s.erase( s.begin()+pos );
				s.erase( s.begin()+(pos-1) );
			}
			else if( s[pos-1]>=s[pos] && pos != s.size()-1 ){
				int times = 1;
				for(int i=2;i<=3;i++){
					if( pos+i >= s.size())break;
					if( s[pos]+i == s[pos]+i-1 )times++;
				}
				sum += s[pos] + s[pos+1]*times;
				rep(i,times+1){
					s.erase( s.begin()+pos );
				}

			}else{
				sum += s[pos];
				s.erase( s.begin()+pos );
			}
		}
		cout<<sum<<endl;
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
using namespace std;
int num[255];

int main() {
    num['I'] = 1;
    num['V'] = 5;
    num['X'] = 10;
    num['L'] = 50;
    num['C'] = 100;
    num['D'] = 1000;
    string s;
    while (cin >> s) {
        int n = num[s.back()];
        for (int i=0; i<(int)s.size()-1; ++i) {
            if (num[s[i]] < num[s[i+1]]) {
                n -= num[s[i]];
            } else {
                n += num[s[i]];
            }
        }
        cout << n << endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
	string buf;
	
	while (cin >> buf) {
		int amount = 0;
		while ( !(buf.empty()) ) {
			switch ( buf.at(0) ) {
			case 'M':
				buf.erase( buf.begin() ); amount += 1000; break;
			case 'D':
				buf.erase( buf.begin() ); amount += 500; break;
			case 'C':
				if ( buf.size() >= 2 ) {
					if ( buf.at(1) == 'M' ) { buf.erase(0,2); amount += 900; break; }
					else if ( buf.at(1) == 'D' ) { buf.erase(0,2); amount += 400; break; }
				}
				buf.erase( buf.begin() ); amount += 100; break;
			case 'L':
				buf.erase( buf.begin() ); amount += 50; break;
			case 'X':
				if ( buf.size() >= 2 ) {
					if ( buf.at(1) == 'C' ) { buf.erase(0,2); amount += 90; break; }
					else if ( buf.at(1) == 'L' ) { buf.erase(0,2); amount += 40; break; }
				}
				buf.erase( buf.begin() ); amount += 10; break;
			case 'V':
				buf.erase( buf.begin() ); amount += 5; break;
			case 'I':
				if ( buf.size() > 1 ) {
					if ( buf.at(1) == 'X' ) { buf.erase(0,2); amount += 9; break; }
					else if ( buf.at(1) == 'V' ) { buf.erase(0,2); amount += 4; break; }
				}
				buf.erase( buf.begin() ); amount += 1; break;
			}
			// cout << buf << endl;
		}
		cout << amount << endl;
	}	
	
	return 0;
}