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 <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


int s[110];
string st;

int main(){
	while(cin>>st){
		rep(i,110) s[i]=0;
		rep(i,st.size()){
			if(st[i]=='I') s[i]=1;
			else if(st[i]=='V') s[i]=5;
			else if(st[i]=='X') s[i]=10;
			else if(st[i]=='L') s[i]=50;
			else if(st[i]=='C') s[i]=100;
			else if(st[i]=='D') s[i]=500;
			else if(st[i]=='M') s[i]=1000;
		}
		int MAX=s[0],num=0;
		int res=0;
		bool f[110];
		rep(i,110) f[i]=true;
		//rep(i,st.size()) cout<<s[i]<<" ";
		//cout<<endl;
		rep(i,st.size()-1){
			if(s[i]<s[i+1]){
				if(f[i]){
					res-=2*s[i];
					f[i]==false;
					f[i+1]=false;
				}
			}
		}
		rep(i,st.size()) res+=s[i];
		cout<<res<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
    string str;
    while(cin >> str) {
        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;

        int ans = 0;
        for(int i = 0; i < str.size(); ++i) {
            char c = str[i];
            if(i+1 < str.size()) {
                char c2 = str[i+1];
                if(m[c] < m[c2]) {
                    ans += m[c2]-m[c];
                    i++;
                    continue;
                }
            }
            ans += m[c];
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
	int pre, cur, ans;
	string str;
	while (cin >> str) {
		pre = cur = ans = 0;
		for (int i = 0; i < str.size(); i++) {
			switch (str[i]) {
				case 'I': cur = 1;		break;
				case 'V': cur = 5;		break;
				case 'X': cur = 10;		break;
				case 'L': cur = 50;		break;
				case 'C': cur = 100;	break;
				case 'D': cur = 500;	break;
				case 'M': cur = 1000;	break;
				default:
					cout << "unknown figure" << endl;
					break;
			}
			if (i == 0) {
				pre = cur;
				continue;
			}
			switch (cur) {
				case 1:
					ans += pre;
					pre = cur;
					break;
				case 5:
				case 10:
					if (pre == 1)
						ans -= pre;
					else
						ans += pre;
					pre = cur;
					break;
				case 50:
				case 100:
					if (pre == 10)
						ans -= pre;
					else
						ans += pre;
					pre = cur;
					break;
				case 500:
				case 1000:
					if (pre == 100)
						ans -= pre;
					else
						ans += pre;
					pre = cur;
					break;
			}
		}
		ans += pre;
		cout << ans << endl;
	}

	return 0;
}

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

int main()
{
	string in;
	int num = 0;
	
	cin >> in;
	
	for(int i=0;i<in.size();++i){
		int f=0,s=0;
		switch(in[i]){
		case 'I':f = 1;		break;
		case 'V':f = 5;		break;
		case 'X':f = 10;	break;
		case 'L':f = 50;	break;
		case 'C':f = 100;	break;
		case 'D':f = 500;	break;
		case 'M':f = 1000;	break;
		}
		switch(in[i+1]){
		case 'I':s = 1;		break;
		case 'V':s = 5;		break;
		case 'X':s = 10;	break;
		case 'L':s = 50;	break;
		case 'C':s = 100;	break;
		case 'D':s = 500;	break;
		case 'M':s = 1000;	break;
		}
		if(f < s){
			num -= f;
		}else{
			num += f;
		}
	}
	
	cout << num << endl;
	
	return 0;
}

C++: // 2011/07/12 Tazoe

#include <iostream>
#include <string>
using namespace std;

int trn(char rom)
{
	switch(rom){
		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;
	}

	return 0;
}

int main()
{
	while(true){
		string str;
		cin >> str;
		if(cin.eof())
			break;

		int sum = 0;
		for(int i=0; i<str.size()-1; i++)
			if(trn(str[i])>=trn(str[i+1]))
				sum += trn(str[i]);
			else
				sum -= trn(str[i]);
		sum += trn(str[str.size()-1]);

		cout << sum << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;

int main(void){
	map <char, int> m;
	vi x;
	int num[] = {1,5,10,50,100,500,1000};
	for (int i=0; i<7; i++)
		m["IVXLCDM"[i]] = num[i];

	while (true){
		string roman;
		cin>>roman;
		if (cin.eof()) break;

		int tmp, tmp2= m[roman[0]];
		for (int i=0; i<(int)roman.size(); i++){
			tmp = m[roman[i]];
			if (i!=0 && tmp2<tmp)
				x[i-1] = -tmp2;
			x.push_back(tmp);
			tmp2 = tmp;
		}

		int s=0;
		for (int i=0; i<(int)x.size(); i++)
			s += x[i];
		cout<<s<<endl;
		x.clear();
	}
}

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

using namespace std;

int main(void){
  string n;
  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 >> n){
    int cnt=0;
    for(int i=0;i<n.size();i++)cnt+=m[n[i]];
    for(int i=0;i<n.size();i++)
      if(m[n[i]]<m[n[i+1]])cnt-=2*m[n[i]];
    cout << cnt << endl;
  }

  return 0;
}

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

using namespace std;

int main(){
  char x[200];
  char roma[7]={'I','V','X','L','C','D','M'};
  int arabia[7]={1,5,10,50,100,500,1000};
  int a,b,ans,ls;
  string s;
  while(cin>>s){
    ans=a=0;
    ls=s.size();
    for(int i=ls-1;i>-1;i--){
      for(int j=0;j<7;j++){
	if(s[i]==roma[j])b=arabia[j];
      }
      if(b>=a){ans+=b;a=b;}
      if(b<a)ans-=b;
    }
    cout<<ans<<endl;
    
  }
}

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

int To_num(char);
int Calculate(string);

int main(void)
{
  string roma;
  
  while(cin >> roma) cout << Calculate(roma) << endl;
  return 0;
}

int Calculate(string str)
{
  int ans = 0;
  int now;
  int next;
  
  for(int i = 0 ; i < str.size() ; i++)
    {
      now = To_num(str[i]);
      if(i != str.size() - 1) next = To_num(str[i+1]);
      else next = -1;

      if(now >= next) ans += now;
      else
	{
	  ans += next - now;
	  i++;
	}
    }
  return ans;
}
      
int To_num(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 -1;
}

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

using namespace std;

int change(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(void){
    char str[100];
    int sum;
    
    while(cin>>str){
        sum=0;
        for(int i=0;i<strlen(str);i++){
            if(change(str[i])>=change(str[i+1])){
                sum+=change(str[i]);
            }
            else{
                sum+=change(str[i+1])-change(str[i]);
                i++;
            }
        }
        cout<<sum<<endl;
    }
    return(0);
}