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 <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

int main(){
	int sum=0;
	string s;
	while(cin >> s){
		s.resize(s.size()+1);
		for(int i=0;i<s.size()-1;++i){
			if(s[i]=='I'){
				if(s[i+1]=='V') sum+=4 , s[i+1]='@';
				else if(s[i+1]=='X') sum+=9 ,s[i+1]='@';
				else if(s[i+1]=='L') sum+=49 , s[i+1]='@';
				else if(s[i+1]=='C') sum+=99 , s[i+1]='@';
				else if(s[i+1]=='D') sum+=499 , s[i+1]='@';
				else if(s[i+1]=='M') sum+=999 , s[i+1]='@';
				else sum+=1;
			} else if (s[i]=='V'){
				if(s[i+1]=='X') sum+=5 , s[i+1]='@';
				else if(s[i+1]=='L') sum+=45 , s[i+1]='@';
				else if(s[i+1]=='C') sum+=95 , s[i+1]='@';
				else if(s[i+1]=='D') sum+=450 , s[i+1]='@';
				else if(s[i+1]=='M') sum+=950 , s[i+1]='@';
				else sum+=5;
			} else if (s[i]=='X'){
				if(s[i+1]=='L') sum+=40 , s[i+1]='@';
				else if(s[i+1]=='C') sum+=90 , s[i+1]='@';
				else if(s[i+1]=='D') sum+=490 , s[i+1]='@';
				else if(s[i+1]=='M') sum+=990 , s[i+1]='@';
				else sum+=10;
			} else if (s[i]=='L'){
				if(s[i+1]=='C') sum+=50 , s[i+1]='@';
				else if(s[i+1]=='D') sum+=450 , s[i+1]='@';
				else if(s[i+1]=='M') sum+=950 , s[i+1]='@';
				else sum+=50;
			} else if (s[i]=='C'){
				if(s[i+1]=='D') sum+=400 , s[i+1]='@';
				else if(s[i+1]=='M') sum+=900 , s[i+1]='@';
				else sum+=100;
			} else if (s[i]=='D'){
				if(s[i+1]=='M') sum+=500 , s[i+1]='@';
				else sum+=500;
			} else if (s[i]=='M'){
				sum+=1000;
			}
		}
		cout << sum << endl;
		sum=0;
	}
	return 0; 
}

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

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (n);++i)
#define repc(i,a,b) for(int i = (a);i <(b);++i)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef vector<int> vi ;
typedef vector<ll> vl ;
//template<class Value>
//using dict = std::map< string, Value >;
typedef map<char,int> dict ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
double eps = 1e-10 ;

template <typename T>
T out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  dict m;
  m['I'] = 1, m['V'] = 5, m['X'] = 10, m['L'] = 50, m['C'] = 100, m['D'] = 500, m['M'] = 1000 ;
  string str;
  bool flag = true;
  vi v(100,0),v2(100,0) ;
  int N,M,y;
  while(cin >> str){
    /*v = v2;
    repc(i,1,str.size()){
      if(m[str[i-1]] > m[str[i]]){
        flag = true ;
      }
      if(m[str[i-1]] < m[str[i]]){
        flag = false ;
      }
      if(flag){
        v[i-1] = m[str[i-1]] ;
      }
      else{
        v[i-1] = -m[str[i-1]] ;
      }
    }
    if(m[str[str.size()-2]] != m[str[str.size()-1]])
    {
      flag =!flag ;
    }
    if(flag){
      v[str.size()-1] = m[str[str.size()-1]] ;
    }
    else{
      v[str.size()-1] = -m[str[str.size()-1]] ;
    }
    cout << accumulate(all(v),0) << endl;*/
  m['I'] = 1, m['V'] = 5, m['X'] = 10, m['L'] = 50, m['C'] = 100, m['D'] = 500, m['M'] = 1000 ;
    y = 0, M = 1001;
    rep(i,str.size()){
      if(str[i] == 'I') N = 1;
      else if(str[i] == 'V') N = 5;
      else if(str[i] == 'X') N = 10;
      else if(str[i] == 'L') N = 50;
      else if(str[i] == 'C') N = 100;
      else if(str[i] == 'D') N = 500;
      else if(str[i] == 'M') N = 1000;
      if(N>M) y -= M*2;
      y += N ;
      M = N ;
    }
    cout << y << endl;
  }
  return 0;
}

C++: // AOJ q0039
// YAMADA Terushige
// 2013.5.6

#include<iostream>
#include<string>
#include<map>
#include<vector>
 
using namespace std;
 
int main(){
  string s;
  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;

  while(cin >> s){
    vector<int> n;
    for (int i = 0;i < s.size() ;i++)
      n.push_back( m[s[i]] );
    for (int i = 1;i < s.size() ;i++)
      if(n[i] > n[i-1]) n[i-1] *= -1;
    int ans = 0;
    for (int i = 0;i < s.size() ;i++)
      ans += n[i];
    cout << ans << endl;
  }
}

C++: #include <bits/stdc++.h>
int from_roman(const std::string &s){
    static const std::map<char, int> m = {
        { 'I', 1 },
        { 'V', 5 },
        { 'X', 10 },
        { 'L', 50 },
        { 'C', 100 },
        { 'D', 500 },
        { 'M', 1000 }
    };
    static const auto get = [&](char c) {
        return m.find(c)->second;
    };
    int n=0;
    for(int i = 0; i < (int)s.size(); ++i){
        if(i + 1 == (int)s.size() || get(s[i]) >= get(s[i+1])) n += get(s[i]);
        else n -= get(s[i]);
    }
    return n;
}

// int to_roman(int n){
//     std::vector<std::pair<std::string, std::string>> res;
//     while(n){
//         int d = n % 10;

//     }
// }

using namespace std;
int main(){
    string n;
    while(cin >> n){
        cout << from_roman(n) << endl;
    }
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	const char RN[] = { 'Z', 'I', 'V', 'X', 'L', 'C', 'D', 'M' }; //
	const int N[] = { 0, 1, 5, 10, 50, 100, 500, 1000 }; 
//	cut here before submit 
//	freopen("testcase.rf", "r", stdin);
	string str = "";
	map<char, int > Ruman;
	int i;
	int even = 5;
	int odd = 1;

	for (i = 0; i < sizeof(RN)/sizeof(RN[0]); ++i){
		Ruman[RN[i]] = N[i];
	} // end for
//	map<char, int>::iterator it = Ruman.begin();
//	for (; it != Ruman.end(); ++it){
//		cout << (*it).first << ':' << (*it).second << endl;
//	} // end for
		
	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		int len = str.length();
		str += 'Z';
		int curr = 0;
		int res = 0;

		
		for (i = 0; i < len; ++i){
			if (Ruman[str[i]] < Ruman[str[i+1]] ){
				curr = -Ruman[str[i]];
			}else{
				curr = Ruman[str[i]];
			} // end if
//			cout << "curr: " << curr << endl;
			res += curr;
			
		} // end for
		cout << res << endl;

	} // end while
			
	return 0;
}

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

using namespace std;

int main(){
  int rta[128];
  rta['Z']=0;
  rta['I']=1;
  rta['V']=5;
  rta['X']=10;
  rta['L']=50;
  rta['C']=100;
  rta['D']=500;
  rta['M']=1000;
  for(string s;cin>>s;){
    s+='Z';
    int ans=0;
    for(int i=0;i<s.size()-1;i++){
      if(rta[s[i]]>=rta[s[i+1]]){
	ans+=rta[s[i]];
      }else{
	ans-=rta[s[i]];
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}