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++: #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 main(){
	string str;
	while(1){
		cin >> str;

		int sum=0;
		stack<int> stk;
		for(int i=0;i<str.size();i++){
			char* pos;
			if((pos = find(name,name+7,str[i])) != name+7){

				if(stk.empty()){
					sum += num[pos - name];
					stk.push(num[pos - name]);
				}

				else if(stk.top() < num[pos - name]){
					sum -= stk.top();
					sum += num[pos - name] - stk.top();
					stk.push(num[pos - name] - stk.top());
				}
				else if(stk.top() >= num[pos - name]){
					sum += num[pos - name];
					stk.push(num[pos - name]);
				}
			}
		}
		cout << sum << endl;

		if(cin.eof()) break;
	}

	
}

C++: #include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<memory>

using namespace std;


int roma( 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 n = 0;
      
      for ( auto i = 0; i < s.size(); ++i )
        {
          if ( i )
            {
              if ( roma( s[i] ) > roma( s[i-1] ) )
                n += roma( s[i] ) - 2 * roma( s[i-1] );
              else
                n += roma( s[i] );
            }
          else
            {
              n += roma( s[i] );
            }
        }
      cout << n << endl;
    }
  
  return 0;
}

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

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

C++: #include<iostream>
#include<string>
#include<map>
using namespace std;
int main() {
	map<char, int> t;
	t['I'] = 1;
	t['V'] = 5;
	t['X'] = 10;
	t['L'] = 50;
	t['C'] = 100;
	t['D'] = 500;
	t['M'] = 1000;
	string str;
	while (cin >> str) {
		int size = str.size();
		int sum = 0;
		for (int i = 0; i < size - 1; i++) {
			if (t[str[i]] < t[str[i + 1]])sum -= t[str[i]];
			else sum += t[str[i]];
		}
		cout << sum + t[str[size - 1]] << endl;
	}
}

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

using namespace std;

int main()
{
    string roman;
    while (cin >> roman) {
        int arabic = 0;
        int left = 1000, right;
        for (size_t i = 0; i < roman.size(); i++) {
            switch (roman.at(i)) {
            case 'M':
                right = 1000;
                break;
            case 'D':
                right = 500;
                break;
            case 'C':
                right = 100;
                break;
            case 'L':
                right = 50;
                break;
            case 'X':
                right = 10;
                break;
            case 'V':
                right = 5;
                break;
            case 'I':
                right = 1;
                break;
            }

            arabic += right;
            if (left < right) {
                arabic -= 2 * left;
            }

            left = right;
        }

        cout << arabic << 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--){
			if(math[i]<math[i-1] && i!=0){num+=(math[i-1]+math[i]); i--;}
			else if(math[i]>math[i-1] && i!=0){num+=(math[i]-math[i-1]); i--;}
			else if(math[i]==math[i-1] || i==0)num+=math[i];
		}
		printf("%d\n",num);
	}
	
return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <cstdio>
#include <set>
#include <map>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> P;


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 s;
	while(cin >> s){
		int ans = 0;
		rep(i, s.size()-1) ans += (m[s[i+1]]>m[s[i]]?-1:1)*m[s[i]]; 
		ans += m[s[s.size()-1]];
		cout << ans << endl;
	}

	return 0;
}

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


int check(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(void){
  string str;
  while(cin >> str){
    int ans = 0;
    for(int i = 0; i < str.size() - 1; i++){
      if(check(str[i]) >= check(str[i+1])) ans += check(str[i]);
      else ans -= check(str[i]);
    }
    ans += check(str[str.size() - 1]);
    cout << ans << endl;
  }
  return 0;
}

C++: #include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>

using namespace std;

static map<char, int> Dictionary;

int ParseRomanNumber(const char *roman) {
  int len = strlen(roman);
  if (len == 0) { return 0; }

  int acc = 0;
  int curr, next = Dictionary[roman[0]];
  for (int i = 1; i < len; ++i) {
    curr = next;
    next = Dictionary[roman[i]];
    acc += curr < next ? -curr : curr;
  }
  acc += Dictionary[roman[len - 1]];
  return acc;
}

int main() {
  Dictionary['I'] = 1;
  Dictionary['V'] = 5;
  Dictionary['X'] = 10;
  Dictionary['L'] = 50;
  Dictionary['C'] = 100;
  Dictionary['D'] = 500;
  Dictionary['M'] = 1000;

  char *line = nullptr;
  size_t buffer_size = 0;
  ssize_t len;
  while ((len = getline(&line, &buffer_size, stdin)) > 0) {
    for (ssize_t i = len - 1; i >= 0 and isspace(line[i]); --i) {
      line[i] = '\0';
    }
    printf("%d\n", ParseRomanNumber(line));
  }
  free(line);

  return 0;
}