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 <bits/stdc++.h>

using namespace std;

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

    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <stdio.h>
using namespace std;
int main(){
	string str;
	while(cin>>str){
		int num=0;
		vector<int> roman;
		for(int i=0;i<str.length();i++){
			if(str[i]=='I'){
				roman.push_back(1);
			}else if(str[i]=='V'){
				roman.push_back(5);
			}else if(str[i]=='X'){
				roman.push_back(10);
			}else if(str[i]=='L'){
				roman.push_back(50);
			}else if(str[i]=='C'){
				roman.push_back(100);
			}else if(str[i]=='D'){
				roman.push_back(500);
			}else if(str[i]=='M'){
				roman.push_back(1000);
			}
		}
		for(int i=0;i<roman.size();i++){
			if(i==roman.size()-1){
				num += roman[roman.size()-1];
			}else{
				if(roman[i]<roman[i+1]){
					num += roman[i+1]-roman[i];
					i++;
				}else{
					num += roman[i];
				}
			}
		}
		cout<<num<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {

	int n;
	char s[128];

	while(cin >> s) {
		n=0;
		for(int i=0; s[i]!='\0'; i++) {
			if(s[i]=='M') {
				n+=1000;
				if(s[i-1]=='D')
					n-=1000;
				else if(s[i-1]=='C')
					n-=200;
				else if(s[i-1]=='L')
					n-=100;
				else if(s[i-1]=='X')
					n-=20;
				else if(s[i-1]=='V')
					n-=10;
				else if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='D') {
				n+=500;
				if(s[i-1]=='C')
					n-=200;
				else if(s[i-1]=='L')
					n-=100;
				else if(s[i-1]=='X')
					n-=20;
				else if(s[i-1]=='V')
					n-=10;
				else if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='C') {
				n+=100;
				if(s[i-1]=='L')
					n-=100;
				else if(s[i-1]=='X')
					n-=20;
				else if(s[i-1]=='V')
					n-=10;
				else if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='L') {
				n+=50;
				if(s[i]=='X')
					n-=20;
				if(s[i-1]=='V')
					n-=10;
				else if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='X') {
				n+=10;
				if(s[i-1]=='V')
					n-=10;
				else if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='V') {
				n+=5;
				if(s[i-1]=='I')
					n-=2;
				continue;
			}
			else if(s[i]=='I')
				n+=1;
		}
		cout << n << endl;

	}

	return 0;

}

C++: #include<iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;

const int ROMA = 256;
int NUM[ROMA];

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

        cout << ans << endl;

    }
    return 0;
}

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

int RomantoArabic(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;
	}

	return -1;
}

int RomanFigure(const std::string& figure)
{
	int temp = RomantoArabic(figure[figure.length()-1]);

	for(size_t i=1; i<figure.length(); ++i)
	{
		temp = RomantoArabic(figure[figure.length()-1-i])<RomantoArabic(figure[(figure.length()-1)-(i-1)]) ?
			temp - RomantoArabic(figure[figure.length()-1-i]) :
			temp + RomantoArabic(figure[figure.length()-1-i]);
	}

	return temp;
}

int main()
{
	std::string figure;

	while(std::cin >> figure)
	{
		std::cout << RomanFigure(figure) << '\n';
	}

}

C++: #include<iostream>
#include<string>
using namespace std;
int dif(int a,int b){
  if(a<b) return b-a;
  else return b+a;
}
int m(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 return 1000;
}
int main(){
  string s;
  while(cin>>s){
    int ans = 0,a[100],count=0;
    a[0] = m(s[0]);
    for(int i=1;i<s.size();i++){
      if(s[i]==s[i-1]) a[count] += m(s[i]);
      else{
	count++;
	a[count] = m(s[i]);
      }
    }
    for(int i=1;i<=count;i+=2) ans += dif(a[i-1],a[i]);
    if(count%2==0) ans += a[count];
    cout << ans << endl;
  }
  return 0;
}

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

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

	string str = "";
	int sum, n;
	while (cin >> str) {
		sum = 0;
		n = 114514;
		for (int i = 0; i < str.size(); i++) {
			if (m[str[i]] <= n) {
				n = m[str[i]];
				sum += n;
			} else {
				sum += m[str[i]];
				sum -= (n * 2);
				n = 114514;
			}
		}
		cout << sum << endl;
	}
	return 0;
}

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

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

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

using namespace std;

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