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<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<vector>
using namespace std;
#define INF (1<<20)
map<string,int> m;
vector<int> num;
main(){
  m["I"]=1;
  m["II"]=2;
  m["III"]=3;
  m["IV"]=4;
  m["V"]=5;
  m["VI"]=6;
  m["VII"]=7;
  m["VIII"]=8;
  m["IX"]=9;
  m["X"]=10;

  m["XI"]=11;
  m["XII"]=12;
  m["XIII"]=13;
  m["XIV"]=14;
  m["XV"]=15;
  m["XVI"]=16;
  m["XVII"]=17;
  m["XVIII"]=18;
  m["XIX"]=19;
  m["XX"]=20;

  m["XXX"]=30;
  m["XL"]=40;
  m["L"]=50;
  m["LX"]=60;
  m["LXX"]=70;
  m["LXXX"]=80;
  m["XC"]=90;
  m["C"]=100;
  m["D"]=500;
  m["M"]=1000;
  string str;
  while(cin >> str){
    int res=0;
    int tmp;
    for(int i=0;i<(int)str.size();i++){
      for(int j=4;j>0;j--){
	if(i+j>str.size()) continue;
	if(m[str.substr(i,j)]>0){
	  num.push_back(m[str.substr(i,j)]);
	  i+=(j-1);
	  break;
	}
      }
    }
    for(int i=0;i<num.size()-1;i++){
      // cout << num[i] << endl;
      if(num[i]>=num[i+1]) res += num[i];
      else{ res += (num[i+1]-num[i]); i++;}
    }
    cout << num.back() << endl;
    res += num.back();
    cout << res << endl;
    num.clear();
  }
}

C++: #include <bits/stdc++.h>

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  map<char,int> T;
  T['I'] = 1;
  T['V'] = 5;
  T['X'] = 10;
  T['L'] = 50;
  T['C'] = 100;
  T['D'] = 500;
  T['M'] = 1000;
  while(cin >> s)
  {
    int ans = 0, p = 0;
    DOWN(i,s.size()-1,0)
    {
      if(T[s[i]] < p) ans -= T[s[i]];
      else ans += T[s[i]];
      p = T[s[i]];
    }
    printf("%d\n",ans);
  }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

int money[256];
int main(){
	money['I'] = 1; money['V'] = 5;
	money['X'] = 10; money['L'] = 50;
	money['C'] = 100; money['D'] = 500;
	money['M'] = 1000;
	
	string in;
	while(cin>>in){
		bool f = false;
		int sum = 0;
		for(int i=in.size()-1; i>=0; i--){
			if( i<in.size()-1 && f ){
				if( money[in[i]]>=money[in[i+1]] ){
					sum += money[in[i]];
				}else{
					sum -= money[in[i]];
					f = false;
				}
			}else{
				sum += money[in[i]];
				f = true;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

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

int main()
{
	int a,m,i;
	int n[256];
	n['I']=1;
	n['V']=5;
	n['X']=10;
	n['L']=50;
	n['C']=100;
	n['D']=500;
	n['M']=1000;

	char s[128];
	while(cin >> s)
	{
		for(a=m=0,i=strlen(s)-1; i>=0; i--)
		{
			if(n[s[i]]<m)	{ a-=n[s[i]]; }
			else			{ a+=m=n[s[i]]; }
		}
		cout << a << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int num(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;
	else{
		return 0;
	}
}
int y[110];
int main() {
	string s;
	int n=0;
	while(true){
		cin>>s;
		if (cin.eof())break; 
		for(int i=0;i<s.size();i++){
			y[i]=num(s[i]);
		}
		for(int i=0;i<s.size();i++){
			if(y[i]>=y[i+1]){
				n+=y[i];
			}
			else{
				n-=y[i];
			}
		}
		cout<<n<<endl;
		n=0;
		for(int i=0;i<110;i++){
			y[i]=0;
		}
	}
}

C++: #include<iostream>
#include<string>
#include<vector>
using namespace std;
string index="IVXLCDM";
int trans[]={1,5,10,50,100,500,1000};
int t_num(char c){
for(int i=0;i<index.size();i++){
if(c==index[i]){
return trans[i];
}
}
}
int main(){
string input;
while(cin>>input){
int ans=0;
vector<int> in;
for(int i=0;i<input.size();i++){
in.push_back(t_num(input[i]));
}
int tmp=0;
tmp=in[0];
for(int i=1;i<in.size();i++){
if(in[i]>in[i-1]){
tmp=in[i]-tmp;
}else if(in[i]<in[i-1]){
ans+=tmp;
tmp=in[i];
}else{
tmp+=in[i];
}
}
ans+=tmp;
cout<<ans<<endl;
}
return 0;
}