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>
using namespace std;

int main(){
    string ss;
    int num[128];
    num['M'] = 1000;
    num['D'] = 500;
    num['C'] = 100;
    num['L'] = 50;
    num['X'] = 10;
    num['V'] = 5;
    num['I'] = 1;
    while( cin >> ss ){
        string::iterator it = ss.begin();
        int answer = 0;
        while( it != ss.end() ){
            if( it+1 == ss.end() ){
                answer += num[ *it ];
            }else if( num[ *it ] < num[ *(it+1) ] ){
                answer += num[ *(it+1) ] - num[ *it ];
                it++;
            }else{
                answer += num[ *it ];
            }
            it++;
        }
        cout << answer << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <utility>
#include <unordered_map>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define bs inline bool scan
ii(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
ii() {return in(gcu());}
bs(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bs(char &c){c=gcu();gcu();return c!=EOF;}
// bs(string &s){int c; s = "";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#undef bs
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
// vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	unordered_map<char, int> mp = {{'I', 1}, {'V', 5},
		{'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};
	for (char c; (c = gcu()) != EOF;) {
		int n = 0, m = mp[c];
		for (;(c = gcu()) != '\n';)
			if (m && m < mp[c])
				n += mp[c] - m, m = 0;
			else
				n += m, m = mp[c];
		n += m;
		out(n, '\n');
	}
}

C++: #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>

using namespace std;

int conv(char c) {
  switch (c) {
  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;
  default:
    return 0;
  }
}

int main() {
  char s[128];
  while (scanf("%s", s) == 1) {
    int r = 0;
    for (char *c = s; *c; c++)
      if (conv(*c) < conv(*(c+1)))
        r -= conv(*c);
      else
        r += conv(*c);
    printf("%d\n", r);
  }
  return 0;
}

C++: #include <iostream>
#include <map>
#include <string>
using namespace std;
#define REP(i,n) for (int i=0; i<n; i++)

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

	char c;
	string r;
	while (cin>>r){
		int tmp, tmp2= m[r[0]], s=0;
		REP(i,r.size()){
			tmp = m[r[i]];
			if (tmp2<tmp)
				s-= tmp2*2;
			s += tmp;
			tmp2 = tmp;
		}
		cout<<s<<endl;
	}
}

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]];
    }
    
    cout << res << endl;
  }
}

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

using namespace std;

int main() {
	string str;
	int ans = 0, buf1=0, buf10=0, buf50=0, buf100=0;
	bool a=false, b=false, c= false, d=false;
	while(cin>>str){
		ans = 0;
		if(cin.eof()) break;
		for(int i=0; i<str.size(); i++){
			switch(str.at(i)){
				case 'I':
					buf1 += 1;
					break;
				case 'V':
					buf1 == 0 ? ans += 5 : ans += 5-buf1;
					buf1 = 0;
					break;
				case 'X':
					buf1 == 0 ? buf10 += 10 : ans += 10-buf1;
					buf1 = 0;
					break;
				case 'L':
					buf10 == 0 ? ans  += 50 : ans += 50-buf10;
					buf10 = 0;
					break;
				case 'C':
					buf10 == 0 ? buf100 += 100 : ans += 100-buf10;
					buf10 = 0;
					break;
				case 'D':
					buf100 == 0 ? ans += 500 : ans += 500-buf100;
					buf100 = 0;
					break;
				case 'M':
					buf100 == 0 ? ans += 1000 : ans += 1000-buf100;
					buf100 = 0;
					break;
			}
		}
		ans += (buf1+buf10+buf100);
		buf1 = buf10 = buf100 = 0;
		cout<<ans<<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 = 0; i < s.size() - 1; i++) {
      if(R[s[i]] < R[s[i + 1]]) res -= R[s[i]];
      else res += R[s[i]];
    }
    cout << res + R[s[s.size() - 1]]<< endl;
  }
}

C++: #include <iostream>
#include <string>
#include <map>
using namespace std;
#define sz(c) int((c).size())

int parse(map<char, int>& m, string& s)
{
  int i, res, cur, next;
  res = 0;
  if (sz(s) == 1)
    return m[s[i]];
  for (int i = 0; i < sz(s) - 1; i++) {
    cur = m[s[i]]; next = m[s[i+1]];
    if (cur < next)
      res -= cur;
    else
      res += cur;
  }
  res += next;
  return res;
}

int main(int argc, char **argv)
{
  string s;
  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;

  for (;;) {
    cin >> s;
    if (cin.eof())
      break;
    cout << parse(m, s) << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    string a;
    int num[101],cou=0,ans;
    while(cin>>a){
        for(int i=0;i<a.size();i++){
        if(a[i]=='I')num[i]=1;
        if(a[i]=='V')num[i]=5;
        if(a[i]=='X')num[i]=10;
        if(a[i]=='L')num[i]=50;
        if(a[i]=='C')num[i]=100;
        if(a[i]=='D')num[i]=500;
        if(a[i]=='M')num[i]=1000;
    }
    ans=num[a.size()-1];
    for(int i=a.size()-1;i>0;i--){
        if(num[i]>num[i-1])ans=ans-num[i-1];
        if(num[i]<=num[i-1])ans=ans+num[i-1];
    }
    cout<<ans<<endl;
}
return 0;
}