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 = value( str[0] );
		
		for( int i = 0; i < strlen( str ) - 1; i++ ){
			if( value( str[i] ) >= value( str[i + 1] ) ){
				ans += value( str[i+1] );
			}
			else{
				if( i == 0 ) ans = 0;
				ans += value( str[i+1] ) - value( str[i] );
				i++;
			}
		}
		
		printf( "%d\n", ans );
	}

 	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	map<char, lint>MP;
	MP['I'] = 1;
	MP['V'] = 5;
	MP['X'] = 10;
	MP['L'] = 50;
	MP['C'] = 100;
	MP['D'] = 500;
	MP['M'] = 1000;
	string S;
	while (cin >> S) {
		reverse(S);
		lint Z = S.size();
		lint ans = 0;
		ans += MP[S[0]];
		for (lint i = 1; i < Z; i++) {
			if (MP[S[i]] >= MP[S[i - 1]]) {
				ans += MP[S[i]];
			}
			else {
				ans -= MP[S[i]];
			}
		}
		cout << ans << enld;
	}
}

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

char num[] = {'I','V','X','L','C','D','M'};
int eqiv[] = {1,5,10,50,100,500,1000};

int id(char el){
	for(int x=0;x<7;++x)
		if(num[x] == el)return x;
	return -1;
}

int main(){	
	string line;
	while(cin>>line){
		int num = 0;
		for(int x=0;x<line.size();++x){
			int c = 1;
			while(x<line.size()+1 && line[x] == line[x+1]){
				c++;x++;
			}
			if(id(line[x])<id(line[x+1])){
				num -= c*eqiv[id(line[x])];
			}else{
				num += c*eqiv[id(line[x])];
			}
			if(line[x]==line[x+1])++x;
		}
		cout<<num<<endl;	
	}
	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) ;
  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;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define prime first
#define weight second
#define MP make_pair
#define PB push_back

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 input;
	while(cin >> input){
		int result = 0;
		if(cin.eof()) break;

		for(int i = 0; i < input.size(); i++){
			if(i ==  input.size() - 1){
				result += table[input[i]];
				break;
			}
			if(table[input[i]] < table[input[i + 1]]) result -= table[input[i]];
			else result += table[input[i]];
		}

		cout << result << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <string>
using namespace std;

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

int solve(string in){
	int ans = 0;
	for (int i = 0; i < in.length()-1; i=i+2){
		int first = toNum(in[i]);
		int second = toNum(in[i + 1]);
		if (first < second){
			ans += (second - first);
		}
		else{
			ans += first;
			ans += second;
		}
	}

	return ans;
}

int main(){
	string in;

	while (cin >> in, !cin.eof()){
		cout << solve(in) << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int check(char x){
    if(x=='M')return 1000;
    else if(x=='D')return 500;
    else if(x=='C')return 100;
    else if(x=='L')return 50;
    else if(x=='X')return 10;
    else if(x=='V')return 5;
    else if(x=='I')return 1;
    else return 0;
}
int main(void){

	char str[100]={0};

	while(cin>>str){
    int ans=0;
        for(int i=0;sizeof(str);i++){
            if(check(str[i])<check(str[i+1]))ans+=(check(str[i+1])-check(str[i])),i++;
            else if(str[i]==0)break;
            else ans+=check(str[i]);

        }

        cout<<ans<<endl;

        for(int i=0;i<sizeof(str);i++){
            str[i]=0;
        }



	}


	return 0;
}