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;
   while(cin>>s)
   {
     int sum=0;
     for(int i=0;i<s.length();i++)
     {
       if(s[i]=='I') 
       {
         if(i+1<s.length()&&s[i+1]!='I') sum-=1;
         else sum+=1;              
       }  
       if(s[i]=='V') sum+=5;
       if(s[i]=='X') sum+=10;
       if(s[i]=='L') sum+=50;  
       if(s[i]=='C') sum+=100;
       if(s[i]=='D') sum+=500;   
       if(s[i]=='M') sum+=1000;    
     }             
     cout<<sum<<endl;
   }
   //while(1);
   return 0;
 }

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

int main(void) {
    map<char,int> a = {{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};
    string str;
    while(getline(cin, str)) {
        int b = 0, c = a[str[0]], d = a[str[0]]; 
        for(int i = 1; i < str.length(); ++i) {
            int e = a[str[i]];
            if (e == d) {
                c += e;
            }
            else if (d < e) {
                b  -=  (c);
                c = e;
            }
            else if (e < d) {
                b += (c);
                c = e;
            }
            d = e;
        }
        b += c;
        cout << b << endl;;
    }
    return 0;
}

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

int main()
{
    string str;

    while( cin >> str )
    {
        int x[str.size()];
        for( int i = 0; i < str.size(); i++ )
        {
            if( str[i] == 'M' )
                x[i] = 1000;
            else if( str[i] == 'D' )
                x[i] = 500;
            else if( str[i] == 'C' )
                x[i] = 100;
            else if( str[i] == 'L' )
                x[i] = 50;
            else if( str[i] == 'X' )
                x[i] = 10;
            else if( str[i] == 'V' )
                x[i] = 5;
            else
                x[i] = 1;
        }

        stack<int> s;
        s.push(x[0]);
        for( int i = 1; i < str.size(); i++ )
        {
            if( s.top() >= x[i] )
            {
                s.push(x[i]);        
            }
            else
            {
                int m = 0;
                while( s.top() < x[i] )
                {
                    m += s.top();
                    s.pop();
                    if( s.empty() == true )     //空なら抜ける。
                        break;
                }
                s.push( x[i] - m );
            }
        }
        int sum = 0;
        while( s.empty() == false )
        {
            sum += s.top();
            s.pop();
        }
        cout << sum << endl;
    }


    return 0;
}

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

int main(){
	char roman[102];
	int i;
	int ans;
	while(cin >> roman){
		i = 0; ans = 0;
		while(roman[i] != '\0'){
			if(roman[i+1] != '\0' && ten(roman[i]) < ten(roman[i+1])) ans = ans - ten(roman[i]);
			else ans = ans + ten(roman[i]);
			i++;
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <math.h>
#include <functional>
#include <algorithm>
#include <utility>
#include <numeric>

typedef long long Int; 
#pragma warning(disable : 4996)
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
#define REPS(a,i,n) for(int i = a ; i < n ; ++i)
using namespace std;

map<char, int> tile;

int main(){
	tile['I'] = 1;
	tile['V'] = 5;
	tile['X'] = 10;
	tile['L'] = 50;
	tile['C'] = 100;
	tile['D'] = 500;
	tile['M'] = 1000;
	tile['WW'] = 99999;

	string a;
	while (cin >> a){
		Int ans(0);

		char before = 'I';
		for (auto i = a.rbegin(); i != a.rend();++i){
			if (tile[before] > tile[*i]){
				ans -= tile[*i];
			}
			else{
				ans += tile[*i];
			}
			before = *i;
		}

		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
int main() {
	std::string s;
	while (std::cin >> s){
		int sum = 0;
		for (int i = 0; i != s.size(); i++){
			if (s[i] == 'I'){
				if (s[i + 1] == 'V') {
					sum += 4;i++;
				}
				else if (s[i + 1] == 'X'){
					sum += 9; i++;
				}
				else sum++;
			}
			else if (s[i] == 'V')sum += 5;
			else if (s[i] == 'X'){
				if (s[i + 1] == 'L'){
					sum += 40;i++;
				}
				else if (s[i + 1] == 'C'){
					sum += 90;i++;
				}
				else sum += 10;
			}
			else if (s[i] == 'L')sum += 50;
			else if (s[i] == 'C') {
				if (s[i + 1] == 'D'){
					sum += 400; i++;
				}
				else if (s[i + 1] == 'M'){
					sum += 900; i++;
				}
				else sum += 100;
			}
			else if (s[i] == 'D')sum += 500;
			else if (s[i] == 'M')sum += 1000;
		}
		std::cout << sum << std::endl;
	}
}

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

int main() {
	int num[14] = {1,5,10,50,100,500,1000,0,3,8,30,80,300,800};
	int nownum;
	int sum;
	char broma;
	char roma;
	string hoge;
	
	while ( cin >> hoge ) {
		sum = 0;
		broma = 10;
		for ( int i = 0; i < hoge.length(); i++ ) {
			roma = hoge[i];
			nownum = string("IVXLCDM").find(roma);
			if ( broma < nownum )
				sum = sum + num[nownum + 7];
			else
				sum = sum + num[nownum];
			broma = nownum;
		}
		cout <<endl << sum << endl;
	}
	
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string t;
    map<char, int> v;
    v['I'] = 1; v['V'] = 5; v['X'] = 10; v['L'] = 50; v['C'] = 100; v['D'] = 500; v['M'] = 1000;
    while(getline(cin, t)){
        int mx = 0, ans = 0;
        for (int i = t.size()-1; i >= 0; --i) {
            if(mx <= v[t[i]]){
                mx = v[t[i]];
                ans += v[t[i]];
            }else {
                ans -= v[t[i]];
            }
        }
        cout << ans << "\n";
    }
    return 0;
}

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;
    }
    cout << abs(sum) << endl;
  }
  return 0;
}