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 <algorithm>

using namespace std;

int translate(char ch){
	switch(ch){
	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 -1; //must not reach here
}

int main(){
	char buf[101];
	int sum;
	bool subFLG;

	while(scanf("%s",buf)!=EOF){
		sum = 0;
		subFLG = false;
		for(int i=0;buf[i] != '\0';i++){
			if(buf[i+1] != '\0' && translate(buf[i]) < translate(buf[i+1]) && subFLG == false){
				sum += -1*(translate(buf[i]));
				subFLG = true;
			}else{
				sum += translate(buf[i]);
				subFLG = false;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<vector>
using namespace std;
#define INF (1<<20)
map<string,int> m;

main(){
  m["I"]=1;
  m["II"]=2;
  m["III"]=3;
  m["IV"]=4;
  m["V"]=5;
  m["VI"]=6;
  m["VII"]=7;
  m["VIII"]=8;
  m["IX"]=9;
  m["X"]=10;

  m["XI"]=11;
  m["XII"]=12;
  m["XIII"]=13;
  m["XIV"]=14;
  m["XV"]=15;
  m["XVI"]=16;
  m["XVII"]=17;
  m["XVIII"]=18;
  m["XIX"]=19;
  m["XX"]=20;

  m["XXX"]=30;
  m["XL"]=40;
  m["L"]=50;
  m["LX"]=60;
  m["LXX"]=70;
  m["LXXX"]=80;
  m["XC"]=90;
  m["C"]=100;
  m["D"]=500;
  m["M"]=1000;
  string str;
  vector<string> num;
  while(cin >> str){
    int res=0;
    int tmp=INF;
    for(int i=0;i<(int)str.size();i++){
      //            cout << res << endl;
      for(int j=4;j>0;j--){
	if(i+j>str.size()) continue;
	if(m[str.substr(i,j)]>0){
	  //    cout << str.substr(i,j) << " " << m[str.substr(i,j)] << endl;
	  if(tmp>=m[str.substr(i,j)]){
	    res+=m[str.substr(i,j)];
	  }else
	    res=m[str.substr(i,j)]-tmp;
	  tmp=m[str.substr(i,j)];
	  i+=(j-1);
	  break;
	}
      }
    }
    cout << res << endl;
  }
}

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

int main(){
  string s;
  while(cin>>s){
    int ans=0, tmp;
    int p, pn;
    vector<int> v;
    for(int i=s.length()-1; i>=0; i--){
      if(s[i]=='I')tmp=1;
      if(s[i]=='V')tmp=5;
      if(s[i]=='X')tmp=10;
      if(s[i]=='L')tmp=50;
      if(s[i]=='C')tmp=100;
      if(s[i]=='D')tmp=500;
      if(s[i]=='M')tmp=1000;

      if(i==s.length()-1){
        p=s.length()-1;
        pn=tmp;
      }

      if(pn!=tmp){
        int tmp2=pn*(p-i);
        p=i;
        pn=tmp;
        if(ans<tmp2)ans+=tmp2;
        else ans-=tmp2;
      }

      if(i==0){
        int tmp2=pn*(p+1);
        if(ans<tmp2)ans+=tmp2;
        else ans-=tmp2;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(){
    string 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;
    while(cin>>str){
        int ans=0;
        for(int i=0;i<str.size();i++){
            if(str.size()==i-1)ans+=M[str[i]];
            else if(M[str[i]]<M[str[i+1]])ans-=M[str[i]];
            else ans+=M[str[i]];
        }
        cout<<ans<<endl;
    }
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


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

bool same(vector<int> n){
	rep(i,n.size()-1){
		if(n[i]!=n[i+1])return false;
	}
	return true;
}
//CCCCLXXXXVIIII
int main(){
	string str;
	while( cin>>str ){
		vector<int> s;
		int sum = 0;

		s.clear();
		rep(i,str.size()) s.pb( toNum(str[i]) );

		while( s.size() ){
			vector<int> tmp;
			int back = s.size()-1;
			for( int i=back;i>=back-3;i-- ){
				tmp.pb(s[i]);
				if( i==0 || ( i!=back && s[i]!=s[i+1] ) )break;
			}
			reverse(all(tmp));

			if( same(tmp) ){
				sum+=tmp[tmp.size()-1];
				s.erase(s.begin()+back);
			}
			else if( tmp[0] <tmp[1]  ){
				sum += tmp[1]-tmp[0];
				s.erase(s.begin()+back);
				s.erase(s.begin()+back-1);
			}
			else{
				sum += tmp[0]+tmp[1]*(tmp.size()-1);
				rep(i,tmp.size()){
					s.erase(s.begin()+(back-i));
				}
			}
		}
		cout<<sum<<endl;
	}
}




/*
		while(1){
			int pos = -1;
			int last = s.size()-1;
			for(i,3){
				if( last-i-1<1 ||  s[last-i]!=s[last-i-1] ){
					pos = last-i-1;
					break;
				}
			}
			if( pos==-1 ){
				sum+=s[last];
				s.erase(s.begin()+last);
			}
			else{
				if( s[pos]<s[pos+1] ){
					sum += s[pos]-s[pos-1];
					s.erase( s.begin()+pos );
					s.erase( s.begin()+(pos-1) );
				}
			}
		}

}



int main(){
	string str;
	while( cin>>str ){
		vector<int> s;
		int sum = 0;

		s.clear();
		rep(i,str.size()) s.pb( toNum(str[i]) );

		while( s.size()>0 ){
			int maxi = -1;
			int pos = -1;
			rep(i,s.size()){
				if( s[i]>=maxi ){
					maxi = s[i];
					pos = i;
				}
			}
			if( pos!=0 && s[pos-1]<s[pos] ){
				sum += s[pos]-s[pos-1];
				s.erase( s.begin()+pos );
				s.erase( s.begin()+(pos-1) );
			}
			else if( s[pos-1]>=s[pos] && pos != s.size()-1 ){
				int times = 1;
				for(int i=2;i<=3;i++){
					if( pos+i >= s.size())break;
					if( s[pos]+i == s[pos]+i-1 )times++;
				}
				sum += s[pos] + s[pos+1]*times;
				rep(i,times+1){
					s.erase( s.begin()+pos );
				}

			}else{
				sum += s[pos];
				s.erase( s.begin()+pos );
			}
		}
		cout<<sum<<endl;
	}
}
*/

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

int translate(char c);

int main()
{
    string line;
    while(cin >> line)
    {
        int buffer = 0;
        int number = 0;
        for(int i=0; i<line.size()-1; i++)
        {
            int current_val = translate(line[i]);
            int next_val = translate(line[i+1]);
            buffer += current_val;
            if(current_val > next_val)
            {
                number += buffer;
                buffer = 0;
            }
            else if(current_val < next_val)
            {
                number -= buffer;
                buffer = 0;
            }
            else
            {
                /* Nop */
            }
        }
        number += buffer;
        number += translate(line[line.size()-1]);
        cout << number << endl;
    }
    return 0;
}

int translate(char c)
{
    int ret_val = 0;
    if(c == 'I')
    {
        ret_val = 1;
    }
    else if(c == 'V')
    {
        ret_val = 5;
    }
    else if(c == 'X')
    {
        ret_val = 10;
    }
    else if(c == 'L')
    {
        ret_val = 50;
    }
    else if(c == 'C')
    {
        ret_val = 100;
    }
    else if(c == 'D')
    {
        ret_val = 500;
    }
    else if(c == 'M')
    {
        ret_val = 1000;
    }
    else
    {
       /* Nop */  
    }
    return ret_val;
}