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>
using namespace std;
int main(){
  string s;
  while(cin >>s){
    int sum = 0, x = 1000, r;
    for(int i=0; i<s.size(); i++){
      if(s[i] == 'I'){r = 1;}
      if(s[i] == 'V'){r = 5;}
      if(s[i] == 'X'){r = 10;}
      if(s[i] == 'L'){r = 50;}
      if(s[i] == 'C'){r = 100;}
      if(s[i] == 'D'){r = 500;}
      if(s[i] == 'M'){r = 1000;}
      if(x>=r){sum+=r;x = r;}
      else{sum+=r-2*x;}
    }
    cout <<sum<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<char,int> CI;
//							1,   5,   10,  50,   100,  500, 1000
const char Roman[] = { 'I', 'V', 'X', 'L', 'C', 'D', 'M' };

int main()
{
//	cut here before submit 
//	freopen ("testcase.RF", "r", stdin );
	map<char,int> trans; trans.clear();
	int m = sizeof (Roman)/sizeof (Roman[0] );
//	vector<CI> trans (m );
	int curr = 1;
	rep (i, m ){
		if (i % 2 == 0 ){
			trans[Roman[i]] = curr;
		}else{
			trans[Roman[i]] = 5*curr;
			curr *= 10;
		} // end if
	} // end rep
/*
	rep (i, m ){
		cout << trans[i].first << ':' << trans[i].second << endl;
	} // end rep
*/


	string str = "";
	while (getline (cin, str ) ){
		int res = 0;
		int n = str.length();
		for (int i = 1; i < n; i++ ){
			int prev = trans[str[i-1]];
			int curr = trans[str[i]];
			if (prev >= curr ){
				res += prev;
			}else{
				res -= prev;
			} // end if
		} // end for
		res += trans[str[n-1]];
		printf ("%d\n", res );
	} // end loop
		
	return 0;
}

C++: #include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str;
	map<char, int>Map;
	Map['I']++;
	Map['V'] = 5;
	Map['X'] = 10;
	Map['L'] = 50;
	Map['C'] = 100;
	Map['D'] = 500;
	Map['M'] = 1000;
	char pre_char = 'I';
	
	while (cin >> str) {
		int ans = 0;
		for (int i = 0; i < str.length(); i++) {
			char this_char = str[i];
			if (i == 0) { pre_char = str[i]; continue; }
			if (Map[this_char] > Map[pre_char]) {
				ans -= Map[pre_char];
			}
			else {
				ans += Map[pre_char];
			}
			pre_char = str[i];
		}
		ans += Map[pre_char];
	}
	return 0;
}

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

main(){
  int i,j,min[3],ans;
  char a[102];
  while(cin >> a){
    ans = 0;
    for(i=0;i<3;i++) min[i] = 0;

    for(i=0;i<102;i++){
      if(a[i] == '\0') break;
      else if(a[i] == 'I'){
	min[0]++;
	ans++;
      }
      else if(a[i] == 'V'){
	ans += 5;
	if(min[0] != 0){
	  ans -= min[0] * 2;
	  min[0] = 0;
	}
      }
      else if(a[i] == 'X'){
	ans += 10;
	if(min[0] != 0){
	  ans -= min[0] * 2;
	  min[0] = 0;
	}
	min[1]++;
      }
      else if(a[i] == 'L'){
	ans += 50;
	if(min[1] != 0){
	  ans -= min[1] * 20;
	  min[1] = 0;
	}
      }
      else if(a[i] == 'C'){
	ans += 100;
	if(min[1] != 0){
	  ans -= min[1] * 20;
	  min[1] = 0;
	}
	min[2]++;
      }
      else if(a[i] == 'D'){
	ans += 500;
	if(min[2] != 0){
	  ans -= min[2] * 200;
	  min[2] = 0;
	}
      }
     else if(a[i] == 'M'){
	ans += 1000;
	if(min[2] != 0){
	  ans -= min[2] * 200;
	  min[2] = 0;
	}
      }
    }

    cout << ans << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

double dot(P a,P b){return real(conj(a)*b);}
double cross(P a,P b){return imag(conj(a)*b);}

int main(){
  int a[255];
  a['I'] = 1;
  a['V'] = 5;
  a['X'] = 10;
  a['L'] = 50;
  a['C'] = 100;
  a['D'] = 500;
  a['M'] = 1000;
  char s[1010];
  while(~scanf("%s",s)){
    int bef = 114514;
    int res = 0;
    int iter = -1;
    while(s[++iter] != '\0'){
      int now = a[s[iter]];
      if(now > bef) res -= bef*2;
      res += now;
      bef = now;
    }
    cout<<res<<endl;
  }
  return 0;
}

C++: using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <vector>
#include <algorithm>
#include <stdio.h>
int CtoI(char c){
	if(c=='I')return 1;
	else if(c=='V')return 5;
	else if(c=='X')return 10;
	else if(c=='L')return 50;
	else if(c=='C')return 100;
	else if(c=='D')return 500;
	else if(c=='M')return 1000;
}
int main()
{
	string s;
	while(getline(cin,s)){
		int ans=0;
		for(int i=1;i<(int)s.length();i++){
			int x=CtoI(s[i-1]);
			if(x<CtoI(s[i]))ans-=x;
			else ans+=x;
		}
		ans+=CtoI(s[(int)s.length()-1]);
		cout<<ans<<endl;
	}
    return 0;
}

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

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

using namespace std;

int convert(char n) {
    switch (n) {
    case 'I': return 1;
    case 'V': return 5;
    case 'X': return 10;
    case 'L': return 50;
    case 'C': return 100;
    case 'D': return 500;
    case 'M': return 1000;
    default: return 0;
    }
}

int main(void) {
    string str;
    while (true) {
        int n = 0;
        cin >> str;
        if (cin.eof()) break;
        for (int i = 0, len = str.size(); i < len; i++) {
            int a = convert(str[i]), b = convert(str[i + 1]);
            if (a < b && i != len - 1) {
                n -= a;
            } else {
                n += a;
            }
        }
        cout << n << endl;
    }
    return 0;
}