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 <string>
#include <cstring>
#include <cmath>
using namespace std;
//I V X L C D M
int main (int argc, char const* argv[]) {
  string raw;
  string map = "IVXLCDM";
  const int weight[7] = {1,5,10,50,100,500,1000};
  while (cin >> raw) {
    int list[7], sum = 0;
    memset(list, 0, sizeof list);
    int loc = map.find(raw[0]);
    sum += weight[loc];
    //cout<<sum<<endl;
    for (int i = 1; i < raw.size(); i += 1) {
      int nloc = map.find(raw[i]);
      if (loc < nloc) {
        sum = sum - weight[nloc];
      } else {
        sum += weight[nloc];
      }
      //cout<<sum<<endl;
      loc = nloc;
    }
    if (sum > 0) cout << sum << endl;
    else cout << -sum << endl;
  }
  return 0;
}

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

using namespace std;

int roman2bin(const string &s){
	int result = 0, maxdig = 0;
	for(int i = s.size() - 1; i >= 0; --i){
		int dig = 0;
		switch(s[i]){
			case 'I': dig =    1; break;
			case 'V': dig =    5; break;
			case 'X': dig =   10; break;
			case 'L': dig =   50; break;
			case 'C': dig =  100; break;
			case 'D': dig =  500; break;
			case 'M': dig = 1000; break;
		}
		if(dig >= maxdig){
			result += dig;
			maxdig = dig;
		}else{
			result -= dig;
		}
	}
	return result;
}

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

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

int func(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;
	}
}

int main() {
	string s;
	while (cin >> s) {
		int sum = func(s.at(s.size() - 1));
		for (int i = s.size() - 1; i > 0; i--) {
			int a = func(s.at(i - 1)),
				b = func(s.at(i));

			if (a < b) {
				sum -= a;
			}
			else {
				sum += a;
			}
		}

		cout << sum << endl;
	}
}

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

int main() {
  string str;
  int size,count = 1,ans = 0,xx[100] = {0};
  char x[100];
  while(cin >> str) {
    char x[100] = {' '};
    int xx[100] = {0};
    size = str.size();
    for(int i=0;i<size;i++) {
      x[i] = *str.substr(i,1).c_str();
      if(x[i] == 'I') {
        xx[i] = 1;
      }
      else if(x[i] == 'V') {
        xx[i] = 5;
      }
      else if(x[i] == 'X') {
        xx[i] = 10;
      }
      else if(x[i] == 'L') {
        xx[i] = 50;
      }
      else if(x[i] == 'C') {
        xx[i] = 100;
      }
      else if(x[i] == 'D') {
        xx[i] = 500;
      }
      else if(x[i] == 'M') {
        xx[i] = 1000;
      }
    }

    for(int i=0;i<size-1;i++) {
      if(xx[i] >= xx[i+1]) {
        ans += xx[i];
        if(i == size-2) {
          ans += xx[i+1];
        }
      }
      else if(xx[i] < xx[i+1]) {
        ans -= xx[i];

        if(i == size-2) {
          ans += xx[i+1];
        }
      }
    }
    cout << ans << endl;
    ans = 0;
  }
}

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

int Roma(char a){
switch(a){
	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(1){
	string a;
	cin>>a;
	if(cin.fail())break;
	int s=0;
	for(int b=0;b<a.length();b++){
		if(a.length()-1==b){
			s+=Roma(a[b]);
		}
		else{
			if(Roma(a[b])<Roma(a[b+1])){
				s+=Roma(a[b+1])-Roma(a[b]);
				b++;
			}
			else s+=Roma(a[b]);
		}
	}
	cout<<s<<endl;
}
}

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

int main()
{
	string in;
	while(cin>>in)
	{
		int ans=0;
		for(int i = 1; i < in.size(); ++i)
		{
			int right=conv(in[i]);
			int left=conv(in[i-1]);
			if(!right||!left) continue;
			if(left<right)
			{
				ans+=right-left;
				in[i]=in[i-1]='0';
			}
		}
		for(int i = 0; i < in.size(); ++i)
		{
			ans+=conv(in[i]);
		}
		cout<<ans<<endl;
	}
  return 0;
}

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

int main(){
	string s;
	while(cin >> s){
		char b[s.size()];
		for(int i=0;i<s.size();i++) b[i] = s[i];
		int k[3] = {1,1,1};
		for(int i=0;i<s.length()-1;i++){
			if(b[i]=='I' and (b[i+1]=='X' or b[i+1]=='V')) k[0] = -1;
			if(b[i]=='X' and (b[i+1]=='L' or b[i+1]=='C')) k[1] = -1;
			if(b[i]=='C' and (b[i+1]=='D' or b[i+1]=='M')) k[2] = -1;
		}
		bool cs = false;
		bool ce = false;
		bool xs = false;
		bool xe = false;
		int w = 0;
		for(int i=0;i<s.length();i++){
			int a;
			if(b[i]=='M') a = 1000;
			if(b[i]=='D') a = 500;
			if(b[i]=='C'){
				if(ce) a = 100*k[2];
				else   a = 100;
				if(not cs) cs = true;
			}
			else if(cs) ce = true;
			if(b[i]=='L') a = 50;
			if(b[i]=='X'){
				if(xe) a = 10*k[1];
				else   a = 10;
				if(not xs) xs = true;
			}
			else if(xs) xe = true;
			if(b[i]=='V') a = 5;
			if(b[i]=='I') a = k[0];
			w += a;
			cout << w << " " << a << endl;
		}
		cout << w << endl;
	}
}

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

main(){
    map<char, int> M;

    M[' '] = 0;
    M['I'] = 1;
    M['V'] = 5;
    M['X'] = 10;
    M['L'] = 50;
    M['C'] = 100;
    M['D'] = 500;
    M['M'] = 1000;

    string line;
    while( cin >> line ){
	line += ' ';
	int sum = 0;
	for ( int i = 0; i < line.size()-1; i++ ){
	    if ( M[line[i]] < M[line[i+1]] ){
		sum -= M[line[i]]; 
	    } else {
		sum += M[line[i]]; 
	    }
	}
	cout << sum << endl;
    }
}

C++: #include <iostream>
#include <string>
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 <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

map<char,int> R;

int main(){
	R['I']=1;
	R['V']=5;
	R['X']=10;
	R['L']=50;
	R['C']=100;
	R['D']=500;
	R['M']=1000;
	string s;
	while(cin >> s){
		if(cin.eof()) break;
		int res=0;
		rep(i,s.size()){
			int cur=R[s[i]];
			if(i+1<s.size()){
				int next=R[s[i+1]];
				if(cur<next)
					res-=cur;
				else
					res+=cur;
			}else
				res+=cur;
		}
		cout << res << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
main(){
  string d="IVXLCDM",s;
  int k[]={1,5,10,50,100,500,1000},a,b;
  while(cin>>s){
    int ans=0;
    for(int i=0;i<s.size();i++){      
      a=b=0;
      for(int j=0;j<7;j++){
	if(s[i]==d[j])a=k[j];
	if(s[i+1]==d[j])b=k[j];
      }
      if(a<b){
	ans+=b-a;
	i++;
      }
      else ans+=a;
    }  
    cout<<ans<<endl;
  }
}