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<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   string s;
   map<char,int> mymap;
   mymap['I']=1;
   mymap['V']=5;
   mymap['X']=10;
   mymap['L']=50;
   mymap['C']=100;
   mymap['D']=500;
   mymap['M']=1000;
   while(cin>>s)
   {
     int sum=0;
     for(int i=0;i<s.length();i++)
     {
       if(i+1<s.length()&&mymap[s[i]]<mymap[s[i+1]]) sum-=mymap[s[i]];
       else sum+=mymap[s[i]];  
     }
     cout<<sum<<endl;
   }
   //while(1);
   return 0;
 }

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		int b[2][100000]={0};bool bb[2][100000]={0};
		for(int i=0;i<100000;i++)for(j=0;j<2;j++)b[j][i]=0;
		for(int i=0;i<100000;i++)for(j=0;j<2;j++)bb[j][i]=0;
		int a[200],sum=0;
	    for(int i=0;i<200;i++)a[i]=0;
		for(int i=0;i<s.size();i++){
			int t;
			if(s[i]=='I')t=1;
			if(s[i]=='V')t=5;
			if(s[i]=='X')t=10;
			if(s[i]=='L')t=50;
			if(s[i]=='C')t=100;
			if(s[i]=='D')t=500;
			if(s[i]=='M')t=1000;
			a[i]=t;
			if(i&&a[i]!=a[i-1]&&b[0][a[i]])b[1][t]++;
			else b[0][t]++;
		}
		for(int i=s.size()-1;i>=0;i--){
			if(sum<a[i]){
				if(i!=s.size()-1&&a[i]!=a[i+1]&&bb[0][a[i]]){
					sum-=b[1][a[i]]*a[i];
				    i-=b[1][a[i]]-1;
				}
				else{sum+=b[0][a[i]]*a[i];
				i-=b[0][a[i]]-1;bb[0][a[i]]=1;}
			}		
			else{
				sum-=b[0][a[i]]*a[i];
				    i-=b[0][a[i]]-1;
				    bb[0][a[i]]=1;
			}
		}
		cout<<sum<<endl;
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  while(cin >>s){
    int ans=0,pro=2000,now;
    for(int i=0; i<s.size(); i++){
      if(s[i] == 'I') now = 1;
      if(s[i] == 'V') now = 5;
      if(s[i] == 'X') now = 10;
      if(s[i] == 'L') now = 50;
      if(s[i] == 'C') now = 100;
      if(s[i] == 'D') now = 500;
      if(s[i] == 'M') now = 1000;
      if(pro>=now){ans+=now;pro = now;}
      else{ans+=(now-pro*2);pro = 2000;}
    }
    cout <<ans<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<cstring>

using namespace std;
int main(void)
{
	char r[1000];
	int kari[1000] = {0};
	while(scanf("%s",r) != EOF)
	{
		int ans = 0;
		int rs = strlen(r);
		for(int i = 0;i < rs;i++)
		{
			     if(r[i] == 'I') kari[i] = 1;
			else if(r[i] == 'V') kari[i] = 5;
			else if(r[i] == 'X') kari[i] = 10;
			else if(r[i] == 'L') kari[i] = 50;
			else if(r[i] == 'C') kari[i] = 100;
			else if(r[i] == 'D') kari[i] = 500;
			else if(r[i] == 'M') kari[i] = 1000;
		}

		for(int i = 0;i < rs;i++)
		{
			if(kari[i] < kari[i+1]) ans -= kari[i];
			else ans += kari[i];
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<map>
using namespace std;
int main() {
	map <char, int> a;
	a.insert(map<char, int>::value_type('I', 1));
	a.insert(map<char, int>::value_type('V', 5));
	a.insert(map<char, int>::value_type('X', 10));
	a.insert(map<char, int>::value_type('L', 50));
	a.insert(map<char, int>::value_type('C', 100));
	a.insert(map<char, int>::value_type('D', 500));
	a.insert(map<char, int>::value_type('M', 1000));
	string c;
	while (cin >> c) {
		string d="";
		for (int i = c.length() - 1; i >= 0; i--)
			d += c[i];
		int sum = 0, e = 0;
		for (int i = 0; i < c.length(); i++) {
			if (a[d[i]] >= e) {
				sum += a[d[i]];
				e = a[d[i]];
			}
			else {
				sum -= a[d[i]];
			}
		}
		cout << sum << endl;
	}
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


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

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

int main() {
	for(string s; cin >> s; ) {
		reverse(all(s));
		int prev = 0, sum = 0;
		rep(i, s.size()) {
			int c = conv(s[i]);
			if(c < prev) sum -= c;
			else sum += c;
			prev = c;
		}
		cout << sum << endl;
	}
	
	return 0;
}

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

using namespace std;

void Solution()
{
    string str;
    
    int a;
    int b;
    int l;
    int x;
    
    char c;
    
    while (getline(cin, str)) //enter
    {
        x = 0;
        
        l = (int)str.size();
        
        for (int i = 0; i < l; i++)
        {
            c = str.at(i); //string text = "ABCDEF";
                            //char ch = text.at( 2 );
            
                 if (c == 'I') a = 1;
            else if (c == 'V') a = 5;
            else if (c == 'X') a = 10;
            else if (c == 'L') a = 50;
            else if (c == 'C') a = 100;
            else if (c == 'D') a = 500;
            else if (c == 'M') a = 1000;
            
            if (i)
            {
                if (b >= a)
                {
                    x += b;
                }
                else
                {
                    x -= b;
                }
            }
            
            b = a;
        }
        
        x += b;
        
        cout << x << endl;
    }
    
}

int main()
{
    Solution();
    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['C']=100;
  ch['D']=500;
  ch['M']=1000;
  
  int ans=0;
  int len=0;
  char s[1111];
  while(cin >> s){
    len=strlen(s);
    s[len]='I';
    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;
  }
}