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<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<vector>
using namespace std;
#define INF (1<<20)
map<string,int> m;

main(){
  m["I"]=1;
  m["II"]=2;
  m["III"]=3;
  m["IV"]=4;
  m["V"]=5;
  m["VI"]=6;
  m["VII"]=7;
  m["VIII"]=8;
  m["IX"]=9;
  m["X"]=10;

  m["XI"]=11;
  m["XII"]=12;
  m["XIII"]=13;
  m["XIV"]=14;
  m["XV"]=15;
  m["XVI"]=16;
  m["XVII"]=17;
  m["XVIII"]=18;
  m["XIX"]=19;
  m["XX"]=20;

  m["XXX"]=30;
  m["XL"]=40;
  m["L"]=50;
  m["LX"]=60;
  m["LXX"]=70;
  m["LXXX"]=80;
  m["XC"]=90;
  m["C"]=100;
  m["D"]=500;
  m["M"]=1000;
  string str;
  vector<string> num;
  while(cin >> str){
    int res=0;
    for(int i=0;i<(int)str.size();i++){
      
      //            cout << res << endl;
      for(int j=4;j>0;j--){
	if(i+j>str.size()) continue;
	if(m[str.substr(i,j)]>0){
	  //    cout << str.substr(i,j) << " " << m[str.substr(i,j)] << endl;
	  if(res>=m[str.substr(i,j)]){
	    res+=m[str.substr(i,j)];
	  }else
	    res=m[str.substr(i,j)]-res;
	  i+=(j-1);
	  break;
	}
      }
    }
    cout << res << endl;
  }
}

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

int main(void){
  string s;
  char c;
  int n1,n2,n;

  while(cin>>s){
    n=0;
    n1=10000;
    for(int i=0;i<s.size();i++){
      c=s[i];
      if(c=='I')n2=1;
      else if(c=='V')n2=5;
      else if(c=='X')n2=10;
      else if(c=='L')n2=50;
      else if(c=='C')n2=100;
      else if(c=='D')n2=500;
      else n2=1000;
      if(n1<n2){
        n-=2*n1;
        n+=n2;
      }
      else{
        n+=n2;
      }
      n1=n2;
    }
    cout<<n<<endl;
  }
  return 0;
}

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

int main(){
	string ss;
	while(cin>>ss){
		vector<int> spot;
		for(int i=0;i<ss.size();i++){
			switch(ss[i]){
				case 'I':
					spot.push_back(1);
					break;
				case 'V':
					spot.push_back(5);
					break;
				case 'X':
					spot.push_back(10);
					break;
				case 'L':
					spot.push_back(50);
					break;
				case 'C':
					spot.push_back(100);
					break;
				case 'D':
					spot.push_back(500);
					break;
				case 'M':
					spot.push_back(1000);
					break;
			}
		}
		int ans=0;
		for(int i=0;i<(spot.size()-1);i++){
			if(spot[i]<spot[i+1]){
				spot[i]*=-1;
			}
			ans+=spot[i];
		}
		ans+=spot[spot.size()-1];
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(){
	int num=0,i,j=0,math[1000]={0};
	char mozi[1000]={0};
	
	while(scanf("%s",mozi)!=EOF){
		num=0;
		for(i=0;i<strlen(mozi);i++){
			if(mozi[i]=='I')math[i]=1;
			else if(mozi[i]=='V')math[i]=5;
			else if(mozi[i]=='X')math[i]=10;
			else if(mozi[i]=='L')math[i]=50;
			else if(mozi[i]=='C')math[i]=100;
			else if(mozi[i]=='D')math[i]=500;
			else if(mozi[i]=='M')math[i]=1000;
		}
		for(i=(strlen(mozi)-1);i>=0;i-=2){
			if(math[i]<=math[i-1] && i!=0)num+=(math[i-1]+math[i]);
			else if(math[i]>math[i-1] && i!=0)num+=(math[i]-math[i-1]);
			else if(i==0)num+=math[i];
		}
		printf("%d\n",num);
	}
	
return 0;
}

C++: #include<iostream>
#include<string>
int main()
{
	auto conv = [](char c)
	{
		switch (c)
		{
		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;
		default:
			return 0;
		}
	};
	for (std::string str; std::cin >> str;)
	{
		str.push_back(' ');
		int sum = 0;
		for (auto itr = str.begin(), end = str.end() - 1; itr != end; itr++)
		{
			sum += conv(*itr) * (conv(*itr) >= conv(*(itr + 1)) ? 1 : -1);
		}
		std::cout << sum << std::endl;
	}
	return 0;
}

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

using namespace std;

int main() {
	string str;
	int ans = 0, buf1=0, buf10=0, buf50=0, buf100=0;
	bool a=false, b=false, c= false, d=false;
	while(cin>>str){
		ans = 0;
		if(cin.eof()) break;
		for(int i=0; i<str.size(); i++){
			switch(str.at(i)){
				case 'I':
					buf1 += 1;
					break;
				case 'V':
					buf1 == 0 ? ans += 5 : ans += 5-buf1;
					buf1 = 0;
					break;
				case 'X':
					buf1 == 0 ? buf10 += 10 : ans += 10-buf1;
					buf1 = 0;
					break;
				case 'L':
					buf10 == 0 ? ans  += 50 : ans += 50-buf10;
					buf10 = 0;
					break;
				case 'C':
					buf10 == 0 ? buf100 += 100 : ans += 100-buf10;
					buf10 = 0;
					break;
				case 'D':
					buf100 == 0 ? ans += 500 : ans += 500-buf100;
					buf100 = 0;
					break;
				case 'M':
					buf100 == 0 ? ans += 1000 : ans += 1000-buf100;
					buf100 = 0;
					break;
			}
		}
		ans += (buf1+buf10+buf100);
		buf1 = buf10 = buf100 = 0;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>

int main(){
	char c;
	char s[20];
	int i, sum;
	while(1 + scanf("%s", &s)){
		i = 0, sum = 0;

		while(s[i]){
			switch(s[i]){
				case 'M':
					sum += 1000;
					break;
				case 'D':
					sum += 500;
					break;
				case 'C':
					sum += 100;
					break;
				case 'L':
					sum += 50;
					break;
				case 'X':
					sum += 10;
					break;
				case 'V':
					sum += 5;
					break;
				case 'I':
					sum += 1;
					break;
			}
			i++;
		}
		if(strstr(s, "CM") || strstr(s, "CD")){
			sum -= 200;
		}
		if(strstr(s, "XC") || strstr(s, "XL")){
			sum -= 20;
		}
		if(strstr(s, "IX") || strstr(s, "IV")){
			sum -= 2;
		}
		printf("%d\n", sum);
	}
	return 0;
}

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

using namespace std;

int main(void){
	
	
	vector<int> temp;
	vector<int> num;
	char ruman_num[100];
	int sum=0;
	
	
	while(scanf("%s",ruman_num)!=EOF){
	
		
		for(int i=0;i<100;i++){
			if(ruman_num[i]=='I'){
				num.push_back(1);
			}else if(ruman_num[i]=='V'){
				num.push_back(5);
			}else if(ruman_num[i]=='X'){
				num.push_back(10);
			}else if(ruman_num[i]=='L'){
				num.push_back(50);
			}else if(ruman_num[i]=='C'){
				num.push_back(100);
			}else if(ruman_num[i]=='D'){
				num.push_back(500);
			}else if(ruman_num[i]=='M'){
				num.push_back(1000);
			}
		}
		
		
		for(int i=0;i<(num.size())-1;i++){
			if(num[i]<num[i+1]){
				temp.push_back(num[i+1]-num[i]);
				i++;
			}else{
				temp.push_back(num[i+1]+num[i]);
			}
		}
			
			
		for(int i=0;i<temp.size();i++){
			sum=sum+temp[i];
		}
			
			
		cout<<sum<<endl;
		temp.clear();
		num.clear();
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

typedef long long ll;
using namespace std;

//char name[] = {'I','V','X','L','C','D','M'};
//int num[] = {1,5,10,50,100,500,1000};

int roma2num(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 str;
	while(1){
		cin >> str;
		int sum=0;
		for(int i=0;i<str.size();i++){
			int next=-1;
			int now = roma2num(str[i]);

			if(i != str.size() - 1){
				next = roma2num(str[i+1]);
			}

			if(now >= next){
				sum += now;
			}else{
				sum += next - now;
				i++;
			}
		}
		cout << sum << endl;

		if(cin.eof()) break;
	}
}