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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


map<char,int> ma;

int main() {
	ma['I'] = 1, ma['V'] = 5, ma['X'] = 10, ma['L'] = 50;
	ma['C'] = 100, ma['D'] = 500, ma['M'] = 1000;
 
	string str;
	while (cin >> str) {
		int res = 0;
		int n = str.size();
		for (int i = 0; i < n-1; ++i) {
			if ( ma[str[i]] < ma[str[i+1]] ) res -= ma[str[i]];
			else res += ma[str[i]];
		}
		res += ma[str[n-1]];

		cout << res << endl;
	}
    return 0;
}

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


int c(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 s;
	while(cin>>s){
		int sum=0, i=0;
		for(; i<s.size()-1; i++){
			if(c(s[i])>=c(s[i+1]))sum+=c(s[i]);
			else
				sum+=c(s[i+1])-c(s[i]), i++;
		}
		if(i<s.size())sum+=c(s[i]);
		cout<<sum<<"\n";
		s.clear();
	}
	return 0;
}

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

using namespace std;

int main()
{
        map<char, int> roman;
        roman['I'] = 1;
        roman['V'] = 5;
        roman['X'] = 10;
        roman['L'] = 50;
        roman['C'] = 100;
        roman['D'] = 500;
        roman['M'] = 1000;
        string str;

        while (cin >> str) {
                stack<int> st;
                int tmp, ans = 0;
                for (unsigned int i = 0; i < str.length(); i++) {
                        if (!st.empty() && (roman[str[i]] > st.top())) {
                                tmp = roman[str[i]] - st.top();
                                st.pop();
                                st.push(tmp);
                        } else {
                                st.push(roman[str[i]]);
                        }
                }
                while (!st.empty()) {
                        ans += st.top();
                        st.pop();
                }

                cout << ans << endl;
        }

        return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
	map<char,int> mp;
	mp['I']=1;
	mp['V']=5;
	mp['X']=10;
	mp['L']=50;
	mp['C']=100;
	mp['D']=500;
	mp['M']=1000;
	string s;
	while(cin>>s){
		int ans=0;
		rep(i,s.size()){
			if(i+1<s.size()&&mp[s[i]]<mp[s[i+1]])ans-=mp[s[i]];
			else ans+=mp[s[i]];
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	int b,s,n,w;
	char r[100];
	while(cin>>r){
		b=0;s=0;w=0;
		for(int i=0;i<100;i++){
			switch(r[i]){
			case 'I':n=1;break;
			case 'V':n=5;break;
			case 'X':n=10;break;
			case 'L':n=50;break;
			case 'C':n=100;break;
			case 'D':n=500;break;
			case 'M':n=1000;break;
			default:w=1;
			}
			if(w)break;
			if(b!=0){
				if(n>b)s-=b;
				else s+=b;
			}
			b=n;
		}
		cout<<s+b<<endl;
	}
}

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

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

int roma_to_arabic(string roma){
  int nums[100];
  for(int i=0;i<roma.length();i++){
    nums[i]=get_arabic(roma[i]);
  }
  for(int i=0;i<roma.length();i+=2){
    if(nums[i]>=nums[i+1])nums[i]=nums[i]+nums[i+1];
    else if(nums[i]<nums[i+1])nums[i]=nums[i+1]-nums[i];
  }

  int retu=0;
  for(int i=0;i<roma.length();i+=2){
    retu+=nums[i];
  }
  return retu;
}
int main(){
  vector<int> answers;
  string roma_num;
  while(cin>>roma_num){
    answers.push_back(roma_to_arabic(roma_num));
  }
  for(int i=0;i<answers.size();i++){
    cout<<answers[i]<<endl;
  }
}

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

int main() {
	int num[14] = {1,5,10,50,100,500,1000,0,3,8,30,80,300,800};
	int nownum;
	int sum;
	char broma;
	char roma;
	string hoge;
	
	while ( cin >> hoge ) {
		sum = 0;
		broma = 10;
		for ( int i = 0; i < hoge.length(); i++ ) {
			roma = hoge[i];
			nownum = string("IVXLCDM").find(roma);
			if ( broma < nownum )
				sum = sum + num[nownum + 7];
			else
				sum = sum + num[nownum];
			broma = nownum;
		}
		cout << sum << endl;
	}
	
}

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

int main() {
  string str;
  int size,count = 1,ans = 0,xx[100] = {0};
  char x[100];
  while(cin >> str) {
    char x[100] = {' '};
    int xx[100] = {0};
    size = str.size();
    for(int i=0;i<size;i++) {
      x[i] = *str.substr(i,1).c_str();
      if(x[i] == 'I') {
        xx[i] = 1;
      }
      else if(x[i] == 'V') {
        xx[i] = 5;
      }
      else if(x[i] == 'X') {
        xx[i] = 10;
      }
      else if(x[i] == 'L') {
        xx[i] = 50;
      }
      else if(x[i] == 'C') {
        xx[i] = 100;
      }
      else if(x[i] == 'D') {
        xx[i] = 500;
      }
      else if(x[i] == 'M') {
        xx[i] = 1000;
      }
    }

    for(int i=0;i<size-1;i++) {
      if(xx[i] >= xx[i+1]) {
        ans += xx[i];
        if(i == size-2) {
          ans += xx[i+1];
        }
      }
      else if(xx[i] < xx[i+1]) {
        ans -= xx[i];

        if(i == size-2) {
          ans += xx[i+1];
        }
      }
    }
    if(size == 1) {
      ans += xx[0];
        }
    cout << ans << endl;
    ans = 0;
  }
}