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

int main() {
	map<char,int> 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(getline(cin,s)>0){
		int sum=0,before=0,tmp=0;
		for(int i=s.size()-1;i>=0;i--){
			if(before>mp[s[i]]){
				sum-=mp[s[i]];
			}else{
				sum+=mp[s[i]];
			}
			before=mp[s[i]];
		}
		cout<<sum<<endl;
	}return 0;
}

C++: #include <iostream>
#include <cmath>
#include <map>
#include <string>
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;

	string s;
	while(cin >> s)
	{
		int ans = 0;
		for(int i=0;i<s.size()-1;i++)
		{
			if(roman[s[i]] >= roman[s[i+1]]) ans += roman[s[i]];
			else ans -= roman[s[i]];	
		}
		ans += roman[s[s.size()-1]];
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
	int a,m,i;
	int n[256];
	n['I']=1;
	n['V']=5;
	n['X']=10;
	n['L']=50;
	n['C']=100;
	n['D']=500;
	n['M']=1000;

	char s[128];
	while(cin >> s)
	{
		for(a=m=0,i=strlen(s)-1; i>=0; i--)
		{
			if(n[s[i]]<m)	{ a-=n[s[i]]; }
			else			{ a+=m=n[s[i]]; }
		}
		cout << a << endl;
	}
}

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

char al[]={'I','V','X','L','C','D','M'};
#define REP(i,n) for(int i=0; i<n; ++i)

int getv(char a)
{
	int ret=1;
	REP(i,7)
	{
		if(a==al[i]) return ret;
		
		if(i%2==0) ret*=5;
		else ret*=2;

	}
}

int main()
{
	string s;
	while(cin >> s)
	{
		s+='I';
		int ret=0;
		REP(i,s.size()-1)
		{
			ret+=getv(s[i])*(getv(s[i]) >= getv(s[i+1]) ? 1:-1);
		}
		cout << ret << endl;
	} 
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

map<char,int> hyo;

main(){
	hyo['I']=1;
	hyo['V']=5;
	hyo['X']=10;
	hyo['L']=50;
	hyo['C']=100;
	hyo['D']=500;
	hyo['M']=1000;
	
	string in;
	while(cin>>in){
		int i=0;
		int sum=0;
		for(int i=0;i<in.size();i++){
			if(i+1==in.size()){
				sum+=hyo[in[i]];
				continue;
			}
			if(hyo[in[i]]<hyo[in[i+1]]){
				sum+=hyo[in[i+1]]-hyo[in[i]];
				++i;
			}else{
				sum+=hyo[in[i]];
			}
		}
		cout<<sum<<endl;
	}
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

string s;
map<char, int> hs;

int main()
{
  hs['I'] = 1;
  hs['V'] = 5;
  hs['X'] = 10;
  hs['L'] = 50;
  hs['C'] = 100;
  hs['D'] = 500;
  hs['M'] = 1000;

  while(cin >> s){
    int res = 0;
    rep(i, s.size()-1){
      if(hs[s[i]] < hs[s[i+1]])  res -= hs[s[i]];
      else res += hs[s[i]];
    }
    res += hs[s[s.size()-1]];
    cout << res << endl;
  }

  return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

string R = "IVXLCDM";
int r[7] = { 1,5,10,50,100,500,1000 };

int RtoA(string s) {
	int re = 0, si = s.size();
	if (si >= 2) {
		for (int i = 6; i >= 0; i--) {
			int a = s.find(R[i]);
			//cout << a << endl;
			if (a != -1) {
				//cout << RtoA(s.substr(0, a)) << " " << RtoA(s.substr(a + 1)) << endl;
				re = r[i] - RtoA(s.substr(0, a)) + RtoA(s.substr(a + 1));
				break;
			}
		}
	}
	else if (si == 1)
		re = r[R.find(s)];

	return re;
}

int main() {
	for (string s; cin >> s;)
		cout << RtoA(s) << endl;
	return 0;
}

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

C++: #include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

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

int main(){
	string s;
	//vector<int> n;
	//int ans;
	while(cin>>s){
		int ans=0;
		vector<int> n;

		for(int i=0; i<s.size(); i++){
			n.push_back(calc(s.at(i)));
		}
		for(int i=0; i<n.size(); i++){
			if(i<n.size()-1){
				if(n[i]<n[i+1])ans-=n[i];
				else ans+=n[i];
			}
			else{
				ans+=n[i];
			}
			//cout<<n[i]<<" "<<ans<<endl;
		}
		cout<<ans<<endl;
	}


}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int rome(char g) {
	switch (g) {
	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 -1;
	}
}
int main() {
	string s;
	while (cin >> s) {
		int sum = 0;
		int i;
		for (i = 0; i < s.length() -1; i++) {
			if (rome(s[i]) < rome(s[i + 1])) {
				sum += rome(s[i + 1]) - rome(s[i]);
				i++;
				//cout << "sum += " << rome(s[i + 1]) - rome(s[i]) << "  ";
			}
			else {
				sum += rome(s[i]);
				//cout << "sum += " << rome(s[i]) << "  ";
			}
			//cout << "sum is " << sum << endl;
		}
		if (i == s.length() - 1)sum += rome(s[i]);
		cout << sum << endl;
	}
	return 0;
}