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<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;
int check(char str);
int counter(int res,char *str);
int main(){
    char str[128]={0};
    while(~scanf("%s",str)){

        /*宣言*/
        int ans = 0,bef = 0;
        int cnt = 1;
        int len = strlen(str);
        int x;
        bool f = false;
        /*宣言終了*/

        reverse(str,str+len);
        rep(i,len){
            x = check(str[i]);
            if(!f){
                bef = x;
                f = true;
                continue;
                cnt++;
            }
            if(bef == x){
                cnt++;
            }
            else if(bef < x){
                ans += cnt*bef;
                cnt = 1;
                bef = x;
            }
            else{
                int coun = counter(i,str);
                ans += (bef*cnt) - (coun*x);
                cnt = 1;
                f = false;
                i += coun-1;
            }
        }
        if(x == bef)ans += cnt*bef;
        printf("%d\n",ans);
    }
	return 0;
}
int check(char str){
    if(str == 'I')return 1;
    if(str == 'V')return 5;
    if(str == 'X')return 10;
    if(str == 'L')return 50;
    if(str == 'C')return 100;
    if(str == 'D')return 500;
    if(str == 'M')return 1000;
}
int counter(int res , char *str){
    int cnt = 1;
    for(int i = res; str[i] != str[res] ; i++){
        cnt++;
    }
    return cnt;
}

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

int main(){
    map<char, int> dec;
    dec['I'] = 1;
    dec['V'] = 5;
    dec['X'] = 10;
    dec['L'] = 50;
    dec['C'] = 100;
    dec['D'] = 500;
    dec['M'] = 1000;
    string in;
    while( cin >> in ){
        int res=0, sub=0;
        for( int i=0; i<in.length()-1; i++ ){
            if( dec[in[i]] > dec[in[i+1]] ){
                res += dec[in[i]];
            }else if( dec[in[i]] < dec[in[i+1]] ){
                res -= sub+dec[in[i]];
                sub = 0;
            }else{
                sub += dec[in[i]];
            }
        }
        res += sub+dec[in[in.length()-1]];
        cout << res << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	map<char, int> roma;
	roma.insert(make_pair('I', 1));
	roma.insert(make_pair('V', 5));
	roma.insert(make_pair('X', 10));
	roma.insert(make_pair('L', 50));
	roma.insert(make_pair('C', 100));
	roma.insert(make_pair('D', 500));
	roma.insert(make_pair('M', 1000));

	char str[128];
	while(scanf("%s", str) != EOF){
		int v = 0;
		rep(i, strlen(str)){
			if(i && roma[str[i-1]]<roma[str[i]])
				v -= roma[str[i-1]]*2;
			v += roma[str[i]];
		}
		printf("%d\n", v);
	}
}

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

using namespace std;

int main() {

	string k;
	char a;

	while(cin >> k) {
		int mae = 0;
		int number;
		int sum = 0;
		int b;
		b = k.size();
		for (int i = 0; i < b; i++) {
			a = k[i];
			 if (a == 'I') {
				number = 1;
			} else if (a == 'V') {
				number = 5;
			} else if (a == 'X') {
				number = 10;
			} else if (a == 'L') {
				number = 50;
			} else if (a == 'C') {
				number = 100;
			} else if (a == 'D') {
				number = 500;
			} else if (a == 'M') {
				number = 1000;
			}

			if (number <= mae || sum == 0) {
				sum += number;
				mae = number;
			} else {
				sum = sum - (mae * 2) + number;
				mae = number;
			}
		}

		cout << sum << endl;
	}
	return 0;
}

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

map<char, int> data;
int ans;

void parse(string str) {
	ans = 0;
	for (int i=0; i<str.size(); i++) {
		int t1 = data[str[i]];
		int t2 = 0;
		if (i != str.size()-1) t2 = data[str[i+1]];
		if (t1 < t2) {
			ans += t2 - t1;
			i++;
		} else {
			ans += t1;
		}
	}
}

int main() {
	string in;

	data['I'] = 1;
	data['V'] = 5;
	data['X'] = 10;
	data['L'] = 50;
	data['C'] = 100;
	data['D'] = 500;
	data['M'] = 1000;
	
	while (cin >> in, !in.empty()) {
		parse(in);
		cout << ans << endl;
		in.clear();
	}
	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 <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>

//#define PI 3.141592653589

using namespace std;


int main()
{
	string input;
	map<char, int> table;
	int num;
	
	table['I'] = 1;
	table['V'] = 5;
	table['X'] = 10;
	table['L'] = 50;
	table['C'] = 100;
	table['D'] = 500;
	table['M'] = 1000;
	
	//cout << table["M"] << endl;
	
	while (cin >> input)
	{
		num = 0;
		//cout << input[0] << endl;
		
		for (int i=0; i<input.length()-1; i++)
		{
			//cout << input[i] << endl;
			//cout << table[ input[i] ] << endl;
			
			if (table[input[i]] < table[input[i+1]])
			{
				num -= table[input[i]];
			} else {
				num += table[input[i]];
			}
			
		}
		num += table[input[input.length()-1]];
		cout << num << endl;
	}
	
	return 0;
}

C++: 	

#include <iostream>
#include <string>
using namespace std;

int main(){
  int n,sum,a,b;
  string s;
  while(cin>>s){
    a=s.size();
    sum=0;
    b=0;
    for(int i=a-1;i>=0;i--){
      if(s[i]=='I')n=1;
      else if(s[i]=='V')n=5;
      else if(s[i]=='X')n=10;
      else if(s[i]=='L')n=50;
      else if(s[i]=='C')n=100;
      else if(s[i]=='D')n=500;
      else if(s[i]=='M')n=1000;

      if(n<b)n*=-1;

      sum+=n;

      b=n;

    }
    cout<<sum<<endl;
  }
  
  return 0;
}