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(to_roman(roman_to_n(s))) << endl;
}

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

using namespace std;

int main(void){
	
	
	vector<int> temp;
	vector<int> num;
	char ruman_num[100]={'0'};
	int sum;
	
	
	while(scanf("%s",ruman_num)!=EOF){
		sum=0;
		
		for(int i=0;i<100;i++){
			if(ruman_num[i]=='I'){
				num.push_back(1);
			}else if(ruman_num[i]=='V'){
				num.push_back(5);
			}else if(ruman_num[i]=='X'){
				num.push_back(10);
			}else if(ruman_num[i]=='L'){
				num.push_back(50);
			}else if(ruman_num[i]=='C'){
				num.push_back(100);
			}else if(ruman_num[i]=='D'){
				num.push_back(500);
			}else if(ruman_num[i]=='M'){
				num.push_back(1000);
			}else if(ruman_num[i]=='0'){
				break;
			}
		}
		
		num.push_back(0);
		for(int i=0;i<(num.size())-1;i++){
			if(num[i]<num[i+1]){
				temp.push_back(num[i+1]-num[i]);
				i++;
			}else{
				temp.push_back(num[i]);
			}
		}
			
			
		for(int i=0;i<temp.size();i++){
			sum=sum+temp[i];
		}
			
			
		cout<<sum<<endl;
		temp.clear();
		num.clear();
		for(int i=0;i<100;i++){
			ruman_num[i]='0';
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<map>
using namespace std;
#define int long long
map<char, int> m={
        {'I',1},
        {'V',5},
        {'X',10},
        {'L',50},
        {'C',100},
        {'D',500},
        {'M',1000},
};
signed main(){
        char buf[256];
        while( scanf("%s", buf) != EOF ){
                int ans = 0;
                for(int i=0; i<256 && buf[i]!=0;i++){
                        if(buf[i+1]==0){
                                ans+=m[buf[i]];
                        }else{
                                if(m[buf[i]]<m[buf[i+1]]) ans-=m[buf[i]];
                                else ans+=m[buf[i]];
                        }
                }
                cout << ans<< endl;
        }
        return 0;
}

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

using namespace std;

int main()
{
	string str;
	while(cin>>str){
		vector<int> Vec;
		for(int i=0; i < str.size();i++){
			if(str[i] == 'I'){
				Vec.push_back(1);
			}else if(str[i] == 'V'){
				Vec.push_back(5);
			}else if(str[i] == 'X'){
				Vec.push_back(10);
			}else if(str[i] == 'L'){
				Vec.push_back(50);
			}else if(str[i] == 'C'){
				Vec.push_back(100);
			}else if(str[i] == 'D'){
				Vec.push_back(500);
			}else if(str[i] == 'M'){
				Vec.push_back(1000);
			}
		}
		
		int sum=0;
		bool flag = false;
		for(int i=0;i<Vec.size()-1;i++){
			// 右側に大きな数が続くとき
			if( Vec[i] < Vec[i+1] ){
				sum += Vec[i+1] - Vec[i];
				// iを一つ進める
				i++;
				flag = true;
			}else{  // 右側に同じ又は小さな数
				sum += Vec[i];
				flag = false;
			}
		}
		// 最後まで足せていない場合は、最後だけ足す
		if( !flag ){
			sum += Vec[ Vec.size()-1 ];
		}
		
		cout<<sum<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		int b[2][100000]={0};bool bb[2][100000]={0};
		int a[200],sum=0;
		for(int i=0;i<s.size();i++){
			int t;
			if(s[i]=='I')t=1;
			if(s[i]=='V')t=5;
			if(s[i]=='X')t=10;
			if(s[i]=='L')t=50;
			if(s[i]=='C')t=100;
			if(s[i]=='D')t=500;
			if(s[i]=='M')t=1000;
			a[i]=t;
			if(i&&a[i]!=a[i-1]&&b[0][a[i]])b[1][t]++;
			else b[0][t]++;
		}
		for(int i=s.size()-1;i>=0;i--){
			if(sum<a[i]){
				if(i!=s.size()-1&&a[i]!=a[i+1]&&bb[0][a[i]]){
					sum-=b[1][a[i]]*a[i];
				    i-=b[1][a[i]]-1;
				}
				else{sum+=b[0][a[i]]*a[i];
				i-=b[0][a[i]]-1;bb[0][a[i]]=1;}
			}		
			else{
				sum-=b[0][a[i]]*a[i];
				    i-=b[0][a[i]]-1;
				    bb[0][a[i]]=1;
			}
		}
		cout<<sum<<endl;
	}
}

C++: #include <iostream>
#include <string>
#include <map>
#include <string.h>

using namespace std;

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

	while ( cin >> str )
	{
		sum = 0;
		for ( int i = 0 ; i < str.size() ; i++ )
		{
			if ( ( i == 0 ) || ( table[str[i]] == table[str[i-1]] ) || ( table[str[i]] < table[str[i-1]] ) )
			{
				sum = sum + table[str[i]];
			}
			else if( table[str[i]] > table[str[i-1]] )
			{
				sum = sum - table[str[i]];
			}
		}
		if ( sum < 0 )
			sum = -sum;

		cout << sum << endl;
	}

	return 0;
}

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

int main(){
  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;
  m['O']=0;
  string s;
  while(cin>>s){
    int ans=0;
    int n=-1;
    char c='O';
    for(string::iterator it=s.begin();it!=s.end();it++){
      if(*it==c) n++;
      else{
	if(m[c]*5==m[*it]||m[c]*10==m[*it]){
	  ans+=m[*it]-m[c]*n;
	  n=0;
	  c=*it;
	  continue;
	}
	else if(n!=-1) ans+=m[c]*n;
	c=*it;
	n=1;
      }
    }
    ans+=m[c]*n;
    cout<<ans<<endl;
  }
  return 0;
}