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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

typedef long long ll;
using namespace std;

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

int main(){
	string str;
	while(1){
		cin >> str;

		int sum=0;
		stack<int> stk;
		for(int i=0;i<str.size();i++){
			char* pos;
			if((pos = find(name,name+7,str[i])) != name+7){

				if(stk.empty()){
					sum += num[pos - name];
					stk.push(num[pos - name]);
				}

				else if(stk.top() < num[pos - name]){
					sum -= stk.top();
					sum += num[pos - name] - stk.top();
					stk.push(num[pos - name]);
				}
				else if(stk.top() >= num[pos - name]){
					sum += num[pos - name];
					stk.push(num[pos - name]);
				}
			}
		}
		cout << sum << endl;

		if(cin.eof()) break;
	}

	
}

C++: #include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
	string loma;
	while(cin >> loma){
		int arabia = 0;
		vector<int> lom(loma.size()+1);
		for (int i = 0; i < loma.size(); i++) {
			switch (loma.at(i)) {
			case 'I':lom.at(i) = 1; break;
			case 'V':lom.at(i) = 5; break;
			case 'X':lom.at(i) = 10; break;
			case 'L':lom.at(i) = 50; break;
			case 'C':lom.at(i) = 100; break;
			case 'D':lom.at(i) = 500; break;
			case 'M':lom.at(i) = 1000; break;
			}
		}
		for (int i = 0; i < loma.size(); i++) {
			if (lom.at(loma.size() - 1 - i) >= lom.at(loma.size() - i))
				arabia += lom.at(loma.size() - 1 - i);
			else
				arabia -= lom.at(loma.size() - 1 - i);
		}
		cout << arabia << endl;
	}
}

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

#define MAX 100

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

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

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

int main(){
	string str;
	int res,now,next;
	while(getline(cin,str)){
		res = 0;
		for(int i = 0;i < str.size();++i){
			now = convert(str[i]);
			next = i + 1 == str.size() ? 0 : convert(str[i+1]);
			if(now >= next) res += now;
			else {
				res += (next - now);
				++i;
			}
		}
		cout << res << endl;
	}
}

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

int main(){
  string s;
  while(cin>>s){
    int ans=0;
    for(int i=0; i<s.length(); i++){
      int tmp;
      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(tmp<=ans)ans+=tmp;
      else ans=tmp-ans;
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <string.h>
using namespace std;
int main(){
  map<char,int> ch;//文字の数字辞書登録
  ch['I']=1;
  ch['V']=5;
  ch['X']=10;
  ch['L']=50;
  ch['C']=100;
  ch['D']=500;
  ch['M']=1000;
  
  int ans=0;
  int len=0;
  char s[1111];
  while(cin >> s){
    len=strlen(s);
    for(int i=0;i<len;i++){
      if(ch[s[i]]<ch[s[i+1]]){//もしも引き算をすべき場合だったら
	ans-=ch[s[i]];
      }else{
	ans+=ch[s[i]];
      }
    }
    cout << ans << endl;
    ans=0;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <functional>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int romanNumberToInt(string s){
  int n = s.size(), i, res = 0;

  rep(i,n){
    if(i < n-1 && s[i] == 'C' && s[i+1] == 'M'){ res += 900; i++; continue;}
    if(i < n-1 && s[i] == 'C' && s[i+1] == 'D'){ res += 400; i++; continue;}
    if(i < n-1 && s[i] == 'X' && s[i+1] == 'C'){ res += 90; i++; continue;}
    if(i < n-1 && s[i] == 'X' && s[i+1] == 'L'){ res += 40; i++; continue;}
    if(i < n-1 && s[i] == 'I' && s[i+1] == 'X'){ res += 9; i++; continue;}
    if(i < n-1 && s[i] == 'I' && s[i+1] == 'V'){ res += 4; i++; continue;}
    if(s[i] == 'M') res += 1000;
    else if(s[i] == 'D') res += 500;
    else if(s[i] == 'C') res += 100;
    else if(s[i] == 'L') res += 50;
    else if(s[i] == 'X') res += 10;
    else if(s[i] == 'V') res += 5;
    else if(s[i] == 'I') res++;
  }

  return res;
}

int main(){
  string in;

  while(cin >> in){
    printf("%d\n",romanNumberToInt(in));
  }

  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

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;
	for(string s;cin>>s;){
		int res=0;
		rep(i,s.size()){
			if(i==s.size()-1)
				res+=table[s[i]];
			else if(table[s[i]]>=table[s[i+1]])
				res+=table[s[i]];
			else
				res-=table[s[i]];
		}
		cout<<res<<endl;
	}
	
	return 0;
}