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<string>
#include<vector>
using namespace std;


int main(){
  int sum,i,j,kari;
  string data, str;
  while(getline(cin, str)) {
    data = "KKKKKKKKKKKKKKKKKKKKKKKKKKKK";
    data = data.replace(0, str.length(), str);
    sum = j = 0;
    
    while(data[j] != 'K'){
      if(data[j] == 'M'){
	sum += 1000;
      }else if(data[j] == 'D'){
	if(data[j + 1] == 'M'){
	  sum += 900;
	    j++;
	}else{
	  sum += 500;
	}
      }else if(data[j] == 'C'){
	if(data[j + 1] == 'D' || data[j + 1] == 'M'){
	  if(data[j + 1] == 'D'){
	    sum += 400;
	    j++;
	  }else{
	    sum += 900;
	    j++;
	  }
	}else{
	  sum += 100;
	}
      }else if(data[j] == 'L'){
	sum += 50;
      }else if(data[j] == 'X'){
	if(data[j+1] == 'L' || data[j+1] == 'C'){
	  if(data[j+1] == 'L'){
	    sum += 40;
	    j++;
	  }else{
	    sum += 90;
	    j++;
	  }
	}else{
	  sum += 10;
	}
      }else if(data[j] == 'V'){
	sum += 5;
      }else if(data[j] == 'I'){
	if(data[j + 1] == 'V' || data[j + 1] == 'X'){
	  if(data[j + 1] == 'V'){
	    sum += 4;
	    j++;
	  }else{
	    sum += 9;
	    j++;
	  }
	}
	else{
	  sum += 1;
	}
      }
      j++;
    }
    
    cout << sum << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }




int main() {
	mapci val;
	val['I'] = 1; val['V'] = 5; val['X'] = 10; val['L'] = 50; val['C'] = 100; val['D'] = 500; val['M'] = 1000;
	
	string in;
	while (cin>>in) {
		int ans = 0;
		for_(i, 0, (int)in.sz) {
			if (i<(int)in.sz-1) {
				if (val[ in[i] ]<val[ in[i+1] ]) { 
					ans += val[ in[i+1] ] - val[ in[i] ];
					i++;
				} else ans += val[ in[i] ];
			} else {
				ans += val[ in[i] ];
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
string str;
int main()
{
  while(cin>>str){
    int ans = 0;
    map<char,int> fig;
    fig['I'] = 1;
    fig['V'] = 5;
    fig['X'] = 10;
    fig['L'] = 50;
    fig['C'] = 100;
    fig['D'] = 500;
    fig['M'] = 1000;
    for(int i = 0;i < str.length();i++){
      if(fig[str[i]] >=fig[str[i+1]]){
	ans +=fig[str[i]];
      }else{
	ans -=fig[str[i]];
      }
    }
    cout <<ans<<endl;
  }	
  return 0;
}

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

int read(string inp);
int ex(char c);

int main(){
    string inp;
    while(cin >>inp){
        inp += "I";
        cout <<read(inp) <<endl;
    }
    return 0;
}

int read(string inp){
    int sum = 0;
    for(int i = 0; i < (inp.size() - 1); i++){
        int now = ex(inp[i]), next = ex(inp[i + 1]);
        if(now >= next){
            sum += now;
        } else{
            sum += (next - now);
            i++;
        }
    }
    return sum;
}

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

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

using namespace std;

int main(void){
	
	
	char ruman_num[100];
	int sum=0,temp[100],num[100];
	
	
	while(cin>>ruman_num){
	
		
		for(int i=0;i<100;i++){
			temp[i]=num[i]=0;
		}
		
		
		for(int i=0;i<100;i++){
			if(ruman_num[i]=='I'){
				num[i]=1;
			}else if(ruman_num[i]=='V'){
				num[i]=5;
			}else if(ruman_num[i]=='X'){
				num[i]=10;
			}else if(ruman_num[i]=='L'){
				num[i]=50;
			}else if(ruman_num[i]=='C'){
				num[i]=100;
			}else if(ruman_num[i]=='D'){
				num[i]=500;
			}else if(ruman_num[i]=='M'){
				num[i]=1000;
			}
		}
		
		
		for(int i=0;i<99;i++){
			if(num[i]==0){
				break;
			}
			if(num[i]<num[i+1]){
				temp[i]=num[i+1]-num[i];
			}
		}
		for(int i=0;i<100;i++){
			sum=sum+temp[i];
		}
		cout<<sum<<endl;
	}
	return 0;
}