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 <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'] = 500;
    num['M'] = 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 in;

  while( cin >> in ) {

    long long int ans = 0;
    long long int b = 0;
    long long int a;
    for( long long int i = 0; i < in.size(); i++ ) {
      if ( in[i] == 'I' ) {
	a = 1;
      }else if ( in[i] == 'V' ) {
	a = 5;
      }else if ( in[i] == 'X' ) {
	a = 10;
      }else if ( in[i] == 'L' ) {
	a = 50;
      }else if ( in[i] == 'C' ) {
	a = 100;
      }else if ( in[i] == 'D' ) {
	a = 500;
      }else if ( in[i] == 'M' ) {
	a = 1000;
      }
      if ( b == 0 ) {
	b = a;
      }else {
	if ( b < a ) {
	  ans -= b;
	  ans += a;
	  b = 0;
	}else {
	  ans += b;
	  b = a;
	}
      }
    }
    ans += b;
    cout << ans << endl;

  }

  return 0;

}

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

using namespace std;

int main(void){

	string mo("IVXLCDM");
	int zi[]={1,5,10,50,100,500,1000};
	int ans;
	string inp;

	while(cin>>inp){
		ans=0;
		if(inp.length()>=2){
			for(int i=0;i<inp.length();i+=2){
				if(zi[mo.find(inp[i])]>=zi[mo.find(inp[i+1])]) ans+=zi[mo.find(inp[i])]+zi[mo.find(inp[i+1])];
				else ans+=zi[mo.find(inp[i+1])]-zi[mo.find(inp[i])];
			}
			if(inp.length()%2==1) ans+=zi[mo.find(inp[inp.length()-1])];
			cout<<ans<<endl;
		}
		else cout<<zi[mo.find(inp[0])]<<endl;
	}


	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#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>
#include <iomanip>


#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

#define sz(a)  int((a).size())
#define FOREACH(it, c) for (typeof((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define FOR(i,count) for (int i = 0; i < (count); 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); }

using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
const int MODULO = 1000000007;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

string s;

string ts = "IVXLCDM";
int ti[] = {1,5,10,50,100,500,1000};

int main(){
	while(cin>>s){
		int ans = 0;
		for (int i = 0; s[i]; i++){
			int pos = ts.find(s[i]);
			int npos = ts.find(s[i+1]);
			if(npos > pos) ans -= ti[pos];
			else ans += ti[pos];
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

typedef long long ll;
using namespace std;

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

int roma2num(char c){
	return c=='I'? 1:
		c=='V'? 5:
		c=='X'? 10:
		c=='L'? 50:
		c=='C'? 100:
		c=='D'? 500: 1000;
}

int main(){

	string str;
	while(cin >> str){
		int sum=0;
		int i=0;
		for(;i<str.size()-1;i++){
			int now = roma2num(str[i]);
			int next = roma2num(str[i+1]);

			if(now >= next){
				sum += now;
			}else{
				sum += next - now;
				i++;
			}
		}

		if(i < str.size()) sum += roma2num(str[i]);

		cout << sum << endl;
	}
}

C++: #include <stdio.h>
#include <iostream>

using namespace std;

int main() {

	char a;
	int mae = 0;
	int number;
	int sum = 0;

	while(cin >> a) {
		if (a == 'I') {
			number = 1;
		} else if (a == 'V') {
			number = 5;
		} else if (a == 'X') {
			number = 10;
		} else if (a == 'L') {
			number = 50;
		} else if (a == 'C') {
			number = 100;
		} else if (a == 'D') {
			number = 500;
		} else if (a == 'M') {
			number = 1000;
		}

		if (number <= mae || sum == 0) {
			sum += number;
			mae = number;
		} else {
			sum = sum - (mae * 2) + number;
			mae = number;
		}

	}

	cout << sum << endl;

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll; 
typedef pair<ll, ll> P;
typedef pair<string, ll> PS;

pair<char,int> table[] = { { 'I', 1 }, { 'V', 5 }, { 'X', 10 }, { 'L', 50 },
{ 'C', 100 }, { 'D', 500 }, { 'M', 1000 } };
string s;
ll ans;
char c;
bool f = 0;

int main(){
	while (cin>>s){
		s += "I";
		ans = 0;
		REP(i, s.size()){
			f = 0;
			REP(j, 7){
				if (s[i] == table[j].first){
					REP(k, 7){
						if (s[i + 1] == table[k].first){
							if (j < k){
								ans += table[k].second - table[j].second;
								f = 1;
							}
							else{
								ans += table[j].second;
							}
						}
					}
				}
			}
			if (f)i++;
		}
		cout << ans << endl;
	}
}

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