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 <vector>
#include <string>

using namespace std;

void solve()
{
	string str;
	while(cin >> str)
	{
		vector<int> Vec;
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] == 'M')
			{
				Vec.push_back(1000);
			}
			else if(str[i] == 'D')
			{
				Vec.push_back(500);
			}
			else if(str[i] == 'C')
			{
				Vec.push_back(100);
			}
			else if(str[i] == 'L')
			{
				Vec.push_back(50);
			}
			else if(str[i] == 'X')
			{
				Vec.push_back(10);
			}
			else if(str[i] == 'V')
			{
				Vec.push_back(5);
			}
			else if(str[i] == 'I')
			{
				Vec.push_back(1);
			}
		}
		int sum = 0;
		bool flag = false;
		for(int i = 0; i < Vec.size() - 1; ++i)
		{
			flag = false;
			if(Vec[i] < Vec[i + 1])
			{
				sum += Vec[i + 1] - Vec[i];
				++i;
				flag = true;
			}
			else
			{
				sum += Vec[i];
			}
		}
		if(!flag)
		{
			sum += Vec[Vec.size() - 1];
		}
		cout << sum << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

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

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

int in(char a){
    switch (a){
            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;
    }
}
int main(){
    string str;
    while(cin>>str){
        vector<int>vec;
        int ans=0;
        for(int i=0;i<str.length();i++){
            vec.push_back(in(str[i]));
        }
        for(int i=0;i<vec.size();i++){
            if(i<vec.size()-1&&vec[i]<vec[i+1]){
                vec[i+1]-=vec[i];
            }
            else{
                ans+=vec[i];
            }
        }
        cout<<ans<<endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <stdio.h>
#include <string>
using namespace std;
int main(){
	int ans=0;
	char c[100]="";
	string str;
	while(cin>>str){
		for(int i=0;i<str.size();i++){
			c[i]=str[i];
			switch(c[i]){
			case'I':
				ans+=1;
				break;
			case'V':
				if(c[i-1]=='I'){
					ans+=3;
					break;
				}else{
					ans+=5;
					break;
				}
			case'X':
				if(c[i-1]=='I'){
					ans+=8;
					break;
				}else{
					ans+=10;
					break;
				}
			case'L':
				if(c[i-1]=='X'){
					ans+=30;
					break;
				}else{
					ans+=50;
					break;
				}
			case'C':
				if(c[i-1]=='X'){
					ans+=80;
					break;
				}else{
					ans+=100;
					break;
				}
			case'D':
				if(c[i-1]=='C'){
					ans+=300;
					break;
				}else{
					ans+=500;
					break;
				}
			case'M':
				ans+=1000;
				break;
			}
		}
		cout<<ans<<endl;
		ans=0;
		int c[100];
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <limits.h>
#include <queue>

#define INF INT_MAX

using namespace std;

int main()
{
  string s;
  for(;cin>>s;)
    {
      int ans=0,tmp=0;
      int n[]={1000,500,100,50,10,5,1};
      string nn="MDCLXVI";
      for(int i=0;i<s.size();i++)
	{
	  for(int j=0;j<nn.size();j++)
	    {
	      if(s[i]==nn[j])
		{
		  ans+=n[j];
		  if(tmp<n[j])
		    ans-=tmp*2;
		  tmp=n[j];
		}
	    }
	}
      cout<<ans<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const string ROMA_STR("MDCLXVI");
const VI ROMA_NUM({1000, 500, 100, 50, 10, 5, 1});

int main(void) {
	string str;

	while (cin >> str) {
		VI nums;
		for (char c : str) {
			nums.push_back(ROMA_NUM[ROMA_STR.find(c)]);
		}

		int total = 0;
		for (int i = 0; i < (int)nums.size(); i++) {
			if (i == (int)nums.size() - 1) {
				total += nums[i];
			} else if (nums[i] >= nums[i + 1]) {
				total += nums[i];
			} else {
				total -= nums[i];
			}
		}

		cout << total << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {

    string s;

    while(cin >> s) {

        int len = s.size();
        int num[len + 1];
        int sum = 0;

        for(int i = 0; i < len; ++i) {
            switch(s[i]) {
                case 'I':
                    num[i] = 1;
                    break;
                case 'V':
                    num[i] = 5;
                    break;
                case 'X':
                    num[i] = 10;
                    break;
                case 'L':
                    num[i] = 50;
                    break;
                case 'C':
                    num[i] = 100;
                    break;
                case 'D':
                    num[i] = 500;
                    break;
                case 'M':
                    num[i] = 1000;
                    break;
            }
        }

        num[len] = 1;

        for(int i = len - 1; i >= 0; --i) {
            if(num[i] < num[i + 1]) {
                sum -= num[i];
            } else {
                sum += num[i];
            }
        }

        cout << sum << endl;

    }

    return 0;

}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	string s;
	map<char, int> ex;
	ex['I'] = 1; ex['V'] = 5; ex['X'] = 10; ex['L'] = 50; 
	ex['C'] = 100; ex['D'] = 500; ex['M'] = 1000;
	
	while(cin >> s)
	{
		int sum = 0;
		for(int i = 0; i < s.size()-1; i++)
		{
			char now = s[i], next = s[i+1];

			if(ex[now] < ex[next])
			{
				sum -= ex[now];
			}
			else
			{
				sum += ex[now]; 
			}
		}
		sum += ex[s[s.size()-1]];
		cout << sum << endl;
	}
}