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<string>
#include<algorithm>

const char roma[7] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
const int cost[7] = {1, 5, 10, 50, 100, 500, 1000};

int main(){
	std::string str;
	while(std::cin >> str){
		int res = 0;

		for(int i = 0; i < str.size(); i++){
			int a = 0, b = 0;
			a = std::find(roma, roma + 7, str[i]) - roma;

			if(i == str.size() - 1)res += cost[a];
			else {
				b = std::find(roma, roma + 7, str[i + 1]) - roma;
				if(a >= b)res += cost[a];
				else if(a < b)res += (cost[b] - cost[a]), i++;
			}
		}

		std::cout << res << std::endl;
	}
	return 0;
}

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

//I は1, V は5, X は10, L は50, C は100, D は500, M は1000,

#define I 1
#define V 5
#define X 10
#define L 50
#define C 100
#define D 500
#define M 1000

using namespace std;

int main(){

	string str;
	//while(cin>>str){
	cin>>str;
		int data[200];
		int sum = 0;
		
		//データの数値化
		for(int i=0;i<str.size();i++){
			switch(str[i]){
				case 'I':
					data[i]=I;
					break;
				case 'V':
					data[i]=V;
					break;
				case 'X':
					data[i]=X;
					break;
				case 'L':
					data[i]=L;
					break;
				case 'C':
					data[i]=C;
					break;
				case 'D':
					data[i]=D;
					break;
				case 'M':
					data[i]=M;
					break;
			}
		}

		for(int i=0;i<str.size();i++){
			if(i==str.size()-1){
				sum+=data[i];
			}
			else{
				if(data[i]<data[i+1]){
					sum+= (data[i+1]-data[i]);
					i++;
				}
				else{
					sum+=data[i];
				}
			}
		}

		cout<<sum<<endl;

		return 0;

}

/*
IV
CCCCLXXXXVIIII
CDXCIX
*/

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

using namespace std;

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

int conv(string str)
{
	int ans=0;
	for(int i=0;i<str.length();i++)
	{
		if(i==str.length()-1)
		{
			ans+=conv(str[i]);
		}
		else if(conv(str[i])<conv(str[i+1]))
		{
			ans-=conv(str[i]);
		}
		else ans+=conv(str[i]);
	}
	return ans;
}

int main(void)
{
	string str;
	while(cin>>str)
	{
		cout<<conv(str)<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int check(char x){
    if(x=='M')return 1000;
    else if(x=='D')return 500;
    else if(x=='C')return 100;
    else if(x=='L')return 50;
    else if(x=='X')return 10;
    else if(x=='V')return 5;
    else if(x=='I')return 1;
    else return 0;
}
int main(void){
 
    char str[100]={0};
 
    while(cin>>str){
    int ans=0;
        for(int i=0;sizeof(str);i++){
            if(check(str[i])<check(str[i+1]))ans+=(check(str[i+1])-check(str[i])),i++;
            else if(str[i]==0)break;
            else ans+=check(str[i]);
 
        }
 
        cout<<ans<<endl;
 
        for(int i=0;i<sizeof(str);i++){
            str[i]=0;
        }
    }
    return 0;
}

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

int main(){

  int ans;
  string s;
  int a,b;
  string d = "IVXLCDM";
  int k[] = {1,5,10,50,100,500,1000};

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

    for(int i=0;i<s.size();i++){
      
      a = b = 0;
      for(int j=0;j<7;j++){
	if(s[i] == d[j]) a = k[j];
	if(s[i+1] == d[j]) b = k[j];
      }

      if(a < b){
	ans += b - a;
	i++;
      }
      else ans += a;

    }
  
    cout << ans << endl;

  }
}

C++: //include
//------------------------------------------
#include <bits/stdc++.h> // only for GCC

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

//repetition
//------------------------------------------
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){
        iter(it,v) os<<*it<<(it+1==v.end()?"":",");
        return os;
    }
    template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){
        return os << "[" << p.dirst << "," << p.second << "]";
    }
}

//clear memory
// ------------------------------------------
#define clr(a,i) memset((a), (i) ,sizeof(a))

int main(){
   int ans;
   string s;
   while(getline(cin,s)){
      ans=0;
      rep(i,s.size()-1){
         if(s[i]=='M') ans+=1000;
         else if(s[i]=='D'){
            if(s[i+1]=='M') ans-=500;
            else ans+=500;
         } else if(s[i]=='C'){
            if(s[i+1]!='D'&&s[i+1]!='M') ans+=100;
            else ans-=100;
         }else if(s[i]=='L'){
            if(s[i+1]!='C'&&s[i+1]!='D'&&s[i+1]!='M') ans+=50;
            else ans-=50;
         }else if(s[i]=='X'){
            if(s[i+1]=='X'||s[i+1]=='V'||s[i+1]=='I') ans+=10;
            else ans-=10;
         }else if(s[i]=='V'){
            if(s[i+1]=='I') ans+=5;
            else ans-=5;
         }else if(s[i]=='I'){
            if(s[i+1]=='I') ans+=1;
            else ans-=1;
         }
      }
      if(s[s.size()-1]=='M') ans+=1000;
      if(s[s.size()-1]=='D') ans+=500;
      if(s[s.size()-1]=='C') ans+=100;
      if(s[s.size()-1]=='L') ans+=50;
      if(s[s.size()-1]=='X') ans+=10;
      if(s[s.size()-1]=='V') ans+=5;
      if(s[s.size()-1]=='I') ans+=1;
      cout << ans << endl;
   }
}

C++: #include <iostream>
using namespace std;
int c2i[256];

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

int main() {
  init();

  string str;
  while(getline(cin, str)) {
    int res = 0;
    for(int i=0; i<str.size(); i++) {
      if(c2i[str[i]] < c2i[str[i+1]]) {
	res -= c2i[str[i]];
      } else {
	res += c2i[str[i]];
      }
    }
    cout << res << endl;
  }
  
  return 0;
}

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

char roma[101];
int r[101];

void init()
{
	for(int i=0;i<101;i++){
		roma[i] = 0;
		r[i] = 0;
	}
}

int main()
{
	init();
	while(cin >> roma){
		for(int i=0;i<100;i++){
			if(roma[i]!=0){
				if(roma[i]=='I')
					r[i]=1;
				else if(roma[i]=='V')
					r[i] = 5;
				else if(roma[i]=='X')
					r[i] = 10;
				else if(roma[i]=='L')
					r[i] = 50;
				else if(roma[i]=='C')
					r[i] = 100;
				else if(roma[i]=='D')
					r[i] = 500;
				else if(roma[i]=='M')
					r[i] = 1000;
			}
		}
		int rem=0;
		for(int i=0;i<100;i++){
			bool flag = true;
			for(int j=i+1;j<100;j++){
				if(r[i] < r[j])
					flag = false;
			}
			if(flag){
				rem = i;
				break;
			}
		}
		int a=0;
		for(int i=0;i<rem;i++){
			a+=r[i];
		}
		int b=0;
		for(int i=rem;i<100;i++){
			b+=r[i];
		}
		cout << a << endl;
		cout << b <<endl;
		cout << b-a << endl;
		init();
	}
	return 0;
}