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 <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1};

int main() {
  string s;

  while(cin >> s) {
    int ans = 0;

    REP(i, s.size()) {
      int tmp, tmp2;
      if(s[i] == 'I') tmp = 1;
      else if(s[i] == 'V') tmp = 5;
      else if(s[i] == 'X') tmp = 10;
      else if(s[i] == 'L') tmp = 50;
      else if(s[i] == 'C') tmp = 100;
      else if(s[i] == 'D') tmp = 500;
      else tmp = 1000;
      
      ans += tmp;
      if(i-1 >= 0) {
	if(s[i-1] == 'I') tmp2 = 1;
	else if(s[i-1] == 'V') tmp2 = 5;
	else if(s[i-1] == 'X') tmp2 = 10;
	else if(s[i-1] == 'L') tmp2 = 50;
	else if(s[i-1] == 'C') tmp2 = 100;
	else if(s[i-1] == 'D') tmp2 = 500;
	else tmp2 = 1000;
	if(tmp > tmp2) ans -= tmp2*2;
      }
    }
    cout << ans << endl; 
  }
}

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

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

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

int main()
{
	string s;

	while (cin >> s) {
		int i = 0, n = 0;

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

			i++;
		}

		cout << n << endl;
	}

	return 0;
}

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

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

map< char, int > R;

void makeR() {
  R['I'] = 1; R['V'] = 5; R['X'] = 10; R['L'] = 50; R['C'] = 100;
  R['D'] = 500; R['M'] = 1000;
}

int main(){
 
  string s;
  makeR();
  while(cin >> s) {
    int res = 0;
    for(int i = s.size() - 2; i >= 0; i -= 2) {
      if(R[s[i]] < R[s[i + 1]]) res += abs(R[s[i]] - R[s[i + 1]]);
      else res += R[s[i]] + R[s[i + 1]];
    }
    
    if(s.size() & 1) res += R[s[0]];
    cout << res << endl;
  }
}

C++: #include <bits/stdc++.h>  

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int number(char s) {
	switch(s) {
		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() {
	string s;
	while(cin >> s) {
		int tmp = number(s[0]);
		int num = number(s[1]);
		int ans;
		if(tmp < num) ans = num - tmp;
		else if(tmp >= num) ans = num + tmp;
		tmp = num; 
		FOR(i, 2, s.size()) {
			num = number(s[i]);
			if(tmp < num) {
				ans -= tmp;
				ans += num - tmp;
			}
			else if(tmp >= num) ans += num;
			tmp = num;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
int from_roman(const std::string &s){
    static const std::map<char, int> m = {
        { 'I', 1 },
        { 'V', 5 },
        { 'X', 10 },
        { 'L', 50 },
        { 'C', 100 },
        { 'D', 500 },
        { 'M', 1000 }
    };
    static const auto get = [&](char c) {
        return m.find(c)->second;
    };
    int n=0;
    for(int i = 0; i < (int)s.size(); ++i){
        if(i == n-1 || get(s[i]) >= get(s[i+1])) n += get(s[i]);
        else n -= get(s[i]);
    }
    return n;
}

// int to_roman(int n){
//     std::vector<std::pair<std::string, std::string>> res;
//     while(n){
//         int d = n % 10;

//     }
// }

using namespace std;
int main(){
    string n;
    while(cin >> n){
        cout << from_roman(n) << endl;
    }
}

C++: #include <string.h>
#include <stdio.h>

char c[200];

int main(){
	int ans;
	int n;
	while(scanf("%s",&c) != EOF){
		n = strlen(c);
		ans = 0;
		for(int i = 0; i < n; i++){
			if(c[i] == 'I'){
				if(c[i + 1] == 'V' || c[i + 1] == 'X'){
					ans -= 1;
				}else{
					ans += 1;
				}
			}
			if(c[i] == 'X'){
				if(c[i + 1] == 'L' || c[i + 1] == 'C'){
					ans -= 10;
				}else{
					ans += 10;
				}
			}
			if(c[i] == 'C'){
				if(c[i + 1] == 'D' || c[i + 1] == 'M'){
					ans -= 100;
				}else{
					ans += 100;
				}
			}
			if(c[i] == 'V'){
				ans += 5;
			}
			if(c[i] == 'L'){
				ans += 50;
			}
			if(c[i] == 'D'){
				ans += 500;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}