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<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string str;
	map<char, int>Map;
	Map['I']++;
	Map['V'] = 5;
	Map['X'] = 10;
	Map['L'] = 50;
	Map['C'] = 100;
	Map['D'] = 500;
	Map['M'] = 1000;
	char pre_char = 'I';
	
	while (cin >> str) {
		int ans = 0;
		for (int i = 0; i < str.length(); i++) {
			char this_char = str[i];
			if (i == 0) { pre_char = str[i]; continue; }
			if (Map[this_char] > Map[pre_char]) {
				ans -= Map[pre_char];
			}
			else {
				ans += Map[pre_char];
			}
			pre_char = str[i];
		}
		ans += Map[pre_char];
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
	string s;
	while(cin >> s) {
		int ans = 0;
		for(int i = 0; i < s.size() - 1; i++) {
			if(f(s[i]) > f(s[i + 1])) {
				ans += f(s[i]);
			}
			else {
				ans -= f(s[i]);
			}
		}
		ans += f(s[s.size()]);
		cout << ans << endl;
	}
}

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

using namespace std;

int main()
{
	map< char, int > table;
	table['A'] = 0;
	table['I'] = 1;
	table['V'] = 5;
	table['X'] = 10;
	table['L'] = 50;
	table['C'] = 100;
	table['D'] = 500;
	table['M'] = 1000;
	string str;
	int sum, sz;

	while ( cin >> str )
	{
		sum = 0;
		sz = str.size();
		str.push_back( 'A' );
		for ( int i = 0 ; i < sz ; i++ )
		{
			if( table[str[i]] < table[str[i+1]] )
				sum = sum - table[str[i]];
			else 
				sum = sum + table[str[i]];
		}
		cout << sum << endl;
	}

	return 0;
}

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

int ans;

int getNum( char ch )
{
	switch( ch )
	{
		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;
	}
}

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

		for( int i = 0; i < str.size(); i++ )
		{
			if( i == str.size() - 1 )
			{
				ans += getNum( str[i] );
				break;
			}

			int a = getNum( str[i] ), b = getNum( str[i+1] );
		
			if( a < b )
				ans -= a;
			else
				ans += a;
		}

		std::cout << ans << std::endl;
	}

	return 0;
}

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

int value( char c )
{
	switch( c ){
		case 'I':
			return 1;
			break;
		case 'V':
			return 5;
			break;
		case 'X':
			return 10;
			break;
		case 'L':
			return 50;
			break;
		case 'C':
			return 100;
			break;
		case 'D':
			return 500;
			break;
		case 'M':
			return 1000;
			break;
	}
}

int main()
{
	char str[101];
	while( scanf( "%s", str ) != EOF ){
	
		int ans = 0;
		
		for( int i = 1; i <= strlen( str ); i++ ){
			if( value( str[i-1] ) >= value( str[i] ) ){
				ans += value( str[i-1] );
			}
			else{
				ans += value( str[i] ) - value( str[i-1] );
				i++;
			}
		}
		
		printf( "%d\n", ans );
	}

 	return 0;
}

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

string alpha = "IVXLCDM";
int val[] = {1, 5, 10, 50, 100, 500, 1000};

int indexOf(int ch) {
  for(int i = 0; i < (int)alpha.size(); i++) {
    if( alpha[i] == ch )
      return i;
  }
  return -1;
}

int main() {
  for(string str; cin >> str; ) {
    int sum = 0;
    for(int i = 0; i < (int)str.size(); i++) {
      if ( i + 1 < (int)str.size() && indexOf( str[i] ) < indexOf(str[i + 1]) ) {
          sum -= val[indexOf(str[i])];
        } else {
          sum += val[indexOf(str[i])];
        }
        }
      cout << sum << endl;
    }
    return 0;
  }

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

int main() {
	string s;
	while(cin >> s) {
		int ans = 0;
		for(int i = 0; i < s.size() - 1; i++) {
			if(f(s[i]) > f(s[i + 1])) {
				ans += f(s[i]);
			}
			else {
				ans += f(s[i + 1]) - f(s[i]);
			}
		}
		ans += f(s[s.size()]);
		cout << ans << endl;
	}
}

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

using namespace std;

int toNum(const string &s){
	int tbl[501];
	tbl['I']=1;
	tbl['V']=5;
	tbl['X']=10;
	tbl['L']=50;
	tbl['C']=100;
	tbl['D']=500;
	tbl['M']=1000;
	int sum=0;
	for(int i=0;i<(int)s.size();i++){
		if(i==0)sum+=tbl[s[i]];
		else if(tbl[s[i]]<=tbl[s[i-1]])sum+=tbl[s[i]];
		else{
			sum+=-2*tbl[s[i-1]]+tbl[s[i]];
		}
	}
	return sum;
}

int main(){

	string s;
	while(cin>>s){
		cout<<toNum(s)<<endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

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

C++: #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)

int main()
{
  string str;
  //  string roman[] = {"I", "V", "X", "L", "C", "D", "M"};
  map<char, int> roman;
  roman['I'] = 1;
  roman['V'] = 5;
  roman['X'] = 10;
  roman['L'] = 50;
  roman['C'] = 100;
  roman['D'] = 500;
  roman['M'] = 1000;

  while(cin>>str){
    int nums[str.size()];
    REP(i,str.size())
      nums[i] = roman[str[i]];

    int dec=0;    
    int begin=0;
    int i=0;
    while(i<str.size()-1){
      if(nums[i] < nums[i+1]){
	for(int j=begin; j<=i; j++){
	  dec += nums[j];
	  nums[j] = 0;
	}
	begin = i+2;
      }
      if(nums[i] > nums[i+1]){
	begin = i+1;
      }
      i++;
    }

    int res=0;
    REP(i,str.size()) res += nums[i];

    cout << res-dec << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

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