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

using namespace std;

int main (void)
{
	string a;

	int f[101];

	while (cin >> a)
	{
		int k = 0,co = 0;
		k = a.size();
		for (int i = 0; i < k; i++)
		{
			string p;
			p = a.substr(i,1);

			if (p == "C")
			{
				f[i] = 100;
			}
			else if (p == "L")
			{
				f[i] = 50;
			}
			else if (p == "D")
			{
				f[i] = 500;
			}
			else if (p == "M")
			{
				f[i] = 1000;
			}
			else if (p == "X")
			{
				f[i] = 10;
			}
			else if (p == "V")
			{
				f[i] = 5;
			}
			else
			{
				f[i] = 1;
			}
		}
		f[k] = 0;

		for (int i = 0; i < k; i++)
		{
			if (f[i] != 0)
			{
				if (f[i] >= f[i + 1])
				{
					co += f[i] + f[i + 1];
					f[i + 1] = 0;
				}
				else
				{
					co += f[i + 1] - f[i];
					f[i + 1] = 0;
				}
			}
		}

		cout << co << endl;
	}
}

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

int main() {
	char c[101],m[7]={'I','V','X','L','C','D','M'};
	int s,i,j,h,n[7]={1,5,10,50,100,500,1000};
  while(gets(c)!=NULL) {
    s=0; h=10;
	for (i=0;i<strlen(c);i++) {
     for (j=0;j<7;j++) if (c[i]==m[j]) break;
	 s+=n[j];
	 if (h<j) s-=n[h]*2;
	 h=j;
	}
    cout << s << endl;
  }
  return 0;
}

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

using namespace std;

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

	return 0;
}

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

int main(){
	string s;
	while(cin >> s){
		char b[s.size()];
		for(int i=0;i<s.size();i++) b[i] = s[i];
		int k[3] = {1,1,1};
		for(int i=0;i<s.length()-1;i++){
			if(b[i]=='I' and (b[i+1]=='X' or b[i+1]=='V')) k[0] = -1;
			if(b[i]=='X' and (b[i+1]=='L' or b[i+1]=='C')) k[1] = -1;
			if(b[i]=='C' and (b[i+1]=='D' or b[i+1]=='M')) k[2] = -1;
		}
		cout << k[1] << endl;
		bool cs = false;
		bool ce = false;
		bool xs = true;
		int w = 0;
		for(int i=0;i<s.length();i++){
			int a;
			if(b[i]=='M') a = 1000;
			if(b[i]=='D') a = 500;
			if(b[i]=='C'){
				if(ce) a = 100*k[2];
				else   a = 100;
				if(not cs) cs = true;
			}
			else if(cs) ce = true;
			if(b[i]=='L') a = 50;
			if(b[i]=='X'){
				if(xs) a = 10*k[1];
				else   a = 10;
				if(xs) xs = false;
			}
			if(b[i]=='V') a = 5;
			if(b[i]=='I') a = k[0];
			w += a;
		}
		cout << w << endl;
	}
}

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

int main()
{
	typedef std::map<char, std::uint32_t> RomanToInt;
	RomanToInt roman_map;
	roman_map.insert(std::make_pair('I', 1U));
	roman_map.insert(std::make_pair('V', 5U));
	roman_map.insert(std::make_pair('X', 10U));
	roman_map.insert(std::make_pair('L', 50U));
	roman_map.insert(std::make_pair('C', 100U));
	roman_map.insert(std::make_pair('D', 500U));
	roman_map.insert(std::make_pair('M', 1000U));

	std::string input;
	while (std::getline(std::cin, input)) {
		std::uint32_t value = 0;
		bool prev_minus = false;
		for (std::uint32_t i = 0; i < input.size(); ++i) {
			std::uint32_t num = roman_map[input[i]];
			if ((not prev_minus) and (i + 1 < input.size())) {
				if (num < roman_map[input[i + 1]]) {
					num = -num;
					prev_minus = true;
				}
			}
			else {
				prev_minus = false;
			}
			value += num;
		}
		std::cout << value << std::endl;
	}

	return 0;
}

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

using namespace std;

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



while(cin>>str){
	len = strlen(str) - 1;
	
	sum = 0;
	for(i = 0; i < len; i++){
	    if(table[str[i]] < table[str[i+1]]){
	    	sum -= table[str[i]];
	    }
	    else{
	        sum += table[str[i]];
	    }
	}
	cout<<sum+table[str[len]]<<endl;
}
    
 return 0;   
}

C++: #include<iostream>
#include<map>
#include<math.h>
#include<cstdio>
#include<cstring>
using namespace std;
main(){
  map<char,int> kioku;
  kioku['I']=1;
  kioku['V']=5;
  kioku['X']=10;
  kioku['L']=50;
  kioku['C']=100;
  kioku['D']=500;
  kioku['M']=1000;
  char tmp[1000];
  char c;
  int num=0;
  int before=0;
  while(cin>>tmp){
    for(int i=0;i<strlen(tmp);i++){
      if(i!=strlen(tmp)-1){
	if(kioku[tmp[i+1]]>kioku[tmp[i]]){
	  num+=abs(kioku[tmp[i]]-kioku[tmp[i+1]]);
	  i++;
	}
	else{
	  num+=kioku[tmp[i]];
	}
      }
      else{
	num+=kioku[tmp[i]];
      }
    }
    cout<<num;
    num=0;
  }
}

C++: //0039
//include-------------------------------------
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<stack>

using namespace std;

//typedef--------------------------------------
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define MP make_pair

//repetition-----------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

//constant-------------------------------------
const double PI = acos(-1.0);

//cout,cin-------------------------------------
#define COUT(x) cout<<(x)<<endl
#define CIN(x) cin>>(x)

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

int main(){
	int ans = 0;
	string st;
	while (CIN(st)){
		 int now = f(st[0]);
		 if (st.size() == 1) ans = now;
		 ans = now;
		 REP(i, st.size() - 1){
			 now >= f(st[i + 1]) ? ans += f(st[i + 1]) : ans += f(st[i + 1]) - now - now;
			 now = f(st[i + 1]);
			 COUT(ans);
		 }
		 COUT(ans);
	}



	return 0;

}