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<stdio.h>
#include<string.h>
#include<math.h>

int value( char c )
{
	switch( c ){
		case 'I':
			return 1;
			break;
		case 'V':
			return 5;
			break;
		case 'X':
			return 10;
			break;
		case 'L':
			return 50;
			break;
		case 'C':
			return 100;
			break;
		case 'D':
			return 500;
			break;
		case 'M':
			return 1000;
			break;
	}
}

int main()
{
	char str[101];
	while( scanf( "%s", str ) != EOF ){
	
		int ans = 0;
		
		for( int i = 0; i < strlen( str ) - 1; i++ ){
			if( value( str[i] ) >= value( str[i + 1] ) ){
				if( i == 0 ) ans += value( str[0] );
				ans += value( str[i+1] );
			}
			else{
				ans += value( str[i+1] ) - value( str[i] );
				i++;
			}
		}
		
		printf( "%d\n", ans );
	}

 	return 0;
}

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

using namespace std;

int main(){

	string str;
	char alph[7] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
	int num[7] = {1, 5, 10, 50, 100, 500, 1000};
	int x, s[100];
	
	while(cin >> str){
		for(int i=0; i<str.length(); i++){
			for(int j=0; j<7; j++){
				if(str[i] == alph[j]){
					s[i] = num[j];
				}
			}
		}
		
		x = s[str.length()-1];
		for(int i=str.length()-2; i>=0; i--){
			if(s[i+1] > s[i]){
				x -= s[i];
			}
			else{
				x += s[i];
			}
		}
		
		cout << x << endl;
		
	}
	
	return 0;
	
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const string ROMA = "IVXLCDM";
const int N[] = {1, 5, 10, 50, 100, 500, 1000};

int main(void){
    map<char, int> cor;
    rep(i, 7) cor[ROMA[i]] = N[i];

    int res, pre;
    for(string in; res = pre = 0, cin >> in; cout << res << endl)
        rep(i, in.size()){
            int cur = cor[in[i]];
            res += cur - (pre < cur ? 2 * pre:0);
            pre = cur;
        }
 
    return 0;
}

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

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;

    // ローマ数字のゼロに相当する文字を'_'と仮定する
    // (本来は存在しない)
    roman['_'] = 0;

    // 入力
    while(1) {
        string input;

        cin >> input;
        if(cin.eof()) break;

        char prev = '_';
        int sum = 0;
        for(auto c : input) {
            // 入力された数字はとりあえず合計に加算する
            sum += roman[c];

            // 0でない今の数字が前の数字よりも大きい場合(例えばIX)は、今の数字から前の数字を引いてあげる。
            // ここで前の数字を２つ分多く足している状態なので、この分を引き算で取り除くと都合がよい事になる。
            // (引き算は前の1文字分のみ考えればよい。即ち、IIXは10-2=8ではなく、1+10-1=10となる点に注意)
            if(roman[prev] == 0 || roman[c] <= roman[prev])
                prev = c;
            else {
                sum -= roman[prev] * 2;
                prev = '_';
            }
        }

        cout << sum << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int x[5];



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

    
    
    string roma;
    while(cin>>roma){
        int before = 9999;
        int now = 0;
        int sum = 0;
        
        for(int i=0; i<roma.length(); i++){
            now = value[roma[i]];
            if(before>=now){
                sum+=now;
                before = now;
            }else{
                sum+=now-before*2;
                before = now;
            }
        }
        
        cout<<sum<<endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<string>
int conv(char c)
{
	switch (c)
	{
	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()
{
	for (std::string str; std::cin >> str;)
	{
		str.push_back(' ');
		int sum = 0;
		for (auto itr = str.begin(), end = str.end(); itr != end; itr++)
		{
			sum += conv(*itr) * (conv(*itr) >= conv(*(itr + 1)) ? 1 : -1);
		}
		std::cout << sum << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	int n;
	while (cin >> s){
		n = 0;
		for (int i = 0; i < s.size(); i++){
			if (s[i] == 'I'){
				if (s[i + 1] == 'V'){
					n += 4;
					i++;
				}
				if (s[i + 1] == 'X'){
					n += 9;
					i++;
				}
				else n += 1;
			}
			else if (s[i] == 'V'){
				n += 5;
			}
			else if (s[i] == 'X'){
				if (s[i + 1] == 'L'){
					n += 40;
					i++;
				}
				else if (s[i + 1] == 'C'){
					n += 90;
					i++;
				}
				else n += 10;
			}
			else if (s[i] == 'L'){
				n += 50;
			}
			else if (s[i] == 'C'){
				if (s[i + 1] == 'D') {
					n += 400;
					i++;
				}else if (s[i + 1] == 'M'){
					n += 900;
					i++;
				}
				else n += 100;
			}
			else if (s[i] == 'D'){
				n += 500;
			}
			else if (s[i] == 'M'){
				n += 1000;
			}
		}
		cout << n << endl;
	}
}

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

int Roman_to_Arabia(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 main(){
	string roman;
	int num;

	while (cin >> roman){
		num = 0;

		for (int i = 0; i < roman.size(); ++i){

			if (Roman_to_Arabia(roman[i]) < Roman_to_Arabia(roman[i + 1]))
				num -= Roman_to_Arabia(roman[i]);
			else
				num += Roman_to_Arabia(roman[i]);			
		}
		cout << num << endl;
	}
	return 0;
}