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 <cstring>
using namespace std;

enum {
  I = 1,
  V = 5,
  X = 10,
  L = 50,
  C = 100,
  D = 500,
  M = 1000
};

int main(void) {
  string Rome;
  int sum;
  
  while(cin >> Rome) {
    sum = 0;
    
    if(Rome.size() == 1) {
      switch(Rome[0]) {
        case 'I' : sum = I;   break;
        case 'V' : sum = V;   break;
        case 'X' : sum = X;   break;
        case 'L' : sum = L;   break;
        case 'C' : sum = C;   break;
        case 'D' : sum = D;   break;
        case 'M' : sum = M;   break;
      }
    } else {
      for(int i = 0; i < Rome.size() - 1; ++i) {
        switch(Rome[i]) {
          case 'I' : {
            if(Rome[i + 1] == 'I') {
              sum += I;
            } else {
              sum -= I;
            }
            break;
          }
          case 'V' :  {
            if(Rome[i + 1] == 'I' || Rome[i + 1] == 'R') {
              sum += V;
            } else {
              sum -= V;
            }
            break;
          }
          case 'X' : {
            if(Rome[i + 1] == 'I' || Rome[i + 1] == 'V' || Rome[i + 1] == 'X') {
              sum += X;
            } else {
              sum -= X;
            }
            break;
          }
          case 'L' : {
            if(Rome[i + 1] != 'C' && Rome[i + 1] != 'D' && Rome[i + 1] != 'M') {
              sum += L;
            } else {
              sum -= L;
            }
            break;
          }
          case 'C' : {
            if(Rome[i + 1] != 'D' && Rome[i + 1] != 'M') {
              sum += C;
            } else {
              sum -= C;
            }
            break;
          }
          case 'D' : {
            if(Rome[i + 1] != 'M') {
              sum += D;
            } else {
              sum -= C;
            }break;
          }
          case 'M' : {
            sum += M;
            break;
          }
        }
      }
      switch(Rome[Rome.size() - 1]) {
        case 'I' : sum += I;   break;
        case 'V' : sum += V;   break;
        case 'X' : sum += X;   break;
        case 'L' : sum += L;   break;
        case 'C' : sum += C;   break;
        case 'D' : sum += D;   break;
        case 'M' : sum += M;   break;
      }
    }
    
    cout << sum << endl;
  }
  return 0;
}

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

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

int cnt=0;
int sc[7] ={1000,500,100,50,10,5,1};
string ss[7] ={"M","D","C","L","X","V","I"}, wk, wwk;
map<string, int> rtb;

//	rep(i,7) rtb.insert(pair<string, int>(ss[i],sc[i]));
	rep(i,7) rtb[ss[i]] = sc[i];
	while(!cin.eof()){
		cin >> wk;
		if(cin.eof()) break;
		int su=0;
		string w1,w2;
		rep(i,wk.size()){
			bool mn = false;
			w1 = wk[i];
			rep2(j,i+1,wk.size()){
				w2 = wk[j];
				if(rtb[w1] < rtb[w2 ]) mn = true;
			}
			if(mn) su -= rtb[w1];
			else   su += rtb[w1];
//			cout << rtb[wwk] << "-";
		}
		cout << su << endl;
		cnt++; if(cnt>50) break;
	}	
	
	return 0;
	
	
}

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

using namespace std;

int main(void){
	
	
	vector<int> temp;
	vector<int> num;
	char ruman_num[100];
	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);
			}
		}
		
		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<string>
using namespace std;
string S; char T[8] = "IVXLCDM"; int X[7] = { 1,5,10,50,100,500,1000 }, l[10000];
int main() {
	while (cin >> S) {
		int cnt = 0;
		for (int i = 0; i < S.size(); i++) {
			for (int j = 0; j < 7;j++){
				if (S[i] == T[j]) { l[i] = j; cnt += X[j]; }
			}
		}
		for (int i = 1; i < S.size(); i++) {
			if (l[i - 1] < l[i]) { cnt -= X[l[i - 1]] * 2; }
		}
		cout << cnt << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){

  int tmpi[7] = {1, 5, 10, 50, 100, 500, 1000};
  int ans;
  string tmpc = "IVXLCDM";
  char s[111];

  while(scanf("%s", s) != EOF){

    ans = 0;

    for(int i = 0; i < strlen(s); i++){

      int n1 = tmpi[tmpc.find(s[i])], n2 = tmpi[tmpc.find(s[i+1])];
      if(i+1 >= strlen(s)) n2 = 0;

      if(n1 < n2){
	ans += (n2 - n1);
	i++;
      }
      else ans += n1;

    }

    cout << ans << endl;

  }
  
  return 0;

}

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

int parse(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(void)
{
	string roman;
	int res = 0;
	int i;

	while(cin >> roman)
	{
		for(i=0; i<roman.size()-1; i++)
		{
			if( parse(roman[i]) >= parse(roman[i+1]) )
				res += parse(roman[i]);
			else
				res -= parse(roman[i]);
		}
		res += parse(roman[roman.size()-1]);
		cout << res << endl;
		res = 0;
	}

	return 0;
}