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;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)

int main() {
    string s;
    int a[51];
    while(cin >> s) {
        memset(a, -1, sizeof(a));
        repr(i,s.length() - 1,0) {
            if(s[i] == 'I') a[i] = 1;
            else if(s[i] == 'V') a[i] = 5;
            else if(s[i] == 'X') a[i] = 10;
            else if(s[i] == 'L') a[i] = 50;
            else if(s[i] == 'C') a[i] = 100;
            else if(s[i] == 'D') a[i] = 500;
            else if(s[i] == 'M') a[i] = 1000;
        }

        int prev = -1, ret = 0;
        repr(i,s.length() - 1,0) {
            if(a[i] >= prev) {
                prev = a[i];
                ret += a[i];
            }
            else {
                ret -= a[i];
            }
        }

        cout << ret << endl;
    }
    return 0;
}

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

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl

#define rep(i,n) for(int i = 0; i < (n);++i)
#define repc(i,a,b) for(int i = (a);i <(b);++i)
#define repa(n,array) for(auto n :(array))

typedef long long ll ;
typedef vector<int> vi ;
typedef vector<ll> vl ;
//template<class Value>
//using dict = std::map< string, Value >;
typedef map<char,int> dict ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
double eps = 1e-10 ;

template <typename T>
T out(vector < T > v)
{
  for(size_t i = 0; i < v.size(); i++)
  {
    debug(v[i]);
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  dict m;
  m['I'] = 1, m['V'] = 5, m['X'] = 10, m['L'] = 50, m['C'] = 100, m['D'] = 500, m['M'] = 1000 ;
  string str;
  bool flag = true;
  vi v(100,0),v2(100,0) ;
  while(cin >> str){
    v = v2;
    repc(i,1,str.size()){
      if(m[str[i-1]] > m[str[i]]){
        flag = true ;
      }
      if(m[str[i-1]] < m[str[i]]){
        flag = false ;
      }
      if(flag){
        v[i-1] = m[str[i-1]] ;
      }
      else{
        v[i-1] = -m[str[i-1]] ;
      }
    }
    if(m[str[str.size()-2]] != m[str[str.size()-1]])
    {
      flag =!flag ;
    }
    if(flag){
      v[str.size()-1] = m[str[str.size()-1]] ;
    }
    else{
      v[str.size()-1] = -m[str[str.size()-1]] ;
    }
    cout << accumulate(all(v),0) << endl;
  }
  return 0;
}

C++: #include <stdio.h>

int main()
{
	int i, j, x, num[100];
	char str[100];

	while(gets(str)){
		i = 0;
		j = 0;

		while(str[i] != '\0'){
			switch(str[i]){
				case 'I':
					x = 1;
					break;
				case 'V':
					x = 5;
					break;
				case 'X':
					x = 10;
					break;
				case 'L':
					x = 50;
					break;
				case 'C':
					x = 100;
					break;
				case 'D':
					x = 500;
					break;
				case 'M':
					x = 1000;
					break;
			}

			if(i == 0) num[j] = x;
			else if(str[i] == str[i-1]) num[j] += x;
			else {j++; num[j] = x;}

			i++;
		}

		i = 0;
		x = 0;
		while(num[i] != '\0'){
			if(num[i] < num[i+1]) x -= num[i];
			else x += num[i];

			i++;
		}

		printf("\n%d", x);
	}

	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    string s;
    while(cin>>s){
        int i=0,v=0,x=0,l=0,c=0,d=0,m=0;
        for(int n=0;n<s.size();n++){
            if(s[n]=='I'){
                i++;
            }
            if(s[n]=='V'){
                v++;
            }
            if(s[n]=='X'){
                x++;
            }
            if(s[n]=='L'){
                l++;
            }
            if(s[n]=='C'){
                c++;
            }
            if(s[n]=='D'){
                d++;
            }
            if(s[n]=='M'){
                m++;
            }
        }
        cout<<m*1000+d*500+c*100+l*50+x*10+v*5+i*1<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

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

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

using namespace std;

int main(void){

	string mo("IVXLCDM");
	int zi[]={1,5,10,50,100,500,1000};
	int ans;
	string inp;

	while(cin>>inp){
		ans=0;
		for(int i=inp.length()-2;i>=0;i-=2){
			if(zi[mo.find(inp[i])]>=zi[mo.find(inp[i+1])]) ans+=zi[mo.find(inp[i])]+zi[mo.find(inp[i+1])];
			else ans+=zi[mo.find(inp[i+1])]-zi[mo.find(inp[i])];
		}
		if(inp.length()%2==1) ans+=zi[mo.find(inp[0])];
		cout<<ans<<endl;
	}


	return 0;
}

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

using namespace std;

int main(){
    string input;
    while(cin >> input){
        int ans = 0;
        for(int i=0; i < input.size(); i++){
            string n = input.substr(i, 1);
            if(n == "I") ans++;
            else if(n == "V") ans+=5;
            else if(n == "X") ans+=10;
            else if(n == "L") ans+=50;
            else if(n == "C") ans+=100;
            else if(n == "D") ans+=500;
            else if(n == "M") ans+=1000;
            if(i != 0){
                if(input.substr(i-1, 1) == "I"){
                    if(n == "V" || n == "X") ans-=2;
                }
                else if(input.substr(i-1, 1) == "X"){
                    if(n == "L" || n == "C") ans-=20;
                }
                else if(input.substr(i-1, 1) == "C"){
                    if(n == "D" || n == "M") ans-=200;
                }
            }
        }
        cout << ans << endl;
    }
}

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

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    string s;

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

    while(cin >> s) {
        long ans = 0;
        for(int i=0; i<s.size()-1; i++) {
            if(conv[s[i]] < conv[s[i+1]])
                ans += conv[s[i]];
            else
                ans -= conv[s[i]];
        }
        ans += conv[s[s.size()-1]];
        cout << ans << endl;
    }

    return 0;
}