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 <string>
using namespace std;

int parseInt(char ch){
	switch(ch){
		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;
	}
}

int main(){
	string str;
	int last, n;
	int ans;
	while(cin >> str){
		ans = last = parseInt(str[0]);
		for (int i = 1; i < str.size(); i++) {
			n = parseInt(str[i]);
			if(n > last){
				ans += (n-last) - last;
			}else{
				ans += n;
			}
			last = n;
		}
		cout << ans << endl;
	}
	return 0;
}

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

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

  string s;
  while(cin >> s)
    {
      int ans = 0;
      for(int i=0;i<s.length();i++)
	{
	  if(i == s.length()-1)
	    {
	      ans += a[s[i]];
	      continue;
	    }
	  if(a[s[i]] >= a[s[i+1]])
	    ans += a[s[i]];
	  else if(a[s[i]] < a[s[i+1]])
	    ans -= a[s[i]];
	}
      cout << ans << endl;
    }
  return 0;
}

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

int translate(char c);

int main()
{
    string line;
    while(cin >> line)
    {
        int buffer = 0;
        int number = 0;
        for(int i=0; i<line.size()-1; i++)
        {
            int current_val = translate(line[i]);
            int next_val = translate(line[i+1]);
            buffer += current_val;
            if(current_val > next_val)
            {
                number += buffer;
                buffer = 0;
            }
            else if(current_val < next_val)
            {
                number -= buffer;
                buffer = 0;
            }
            else
            {
                /* Nop */
            }
        }
        number += buffer;
        number += translate(line[line.size()-1]);
        cout << number << endl;
    }
    return 0;
}

int translate(char c)
{
    int ret_val = 0;
    if(c == 'I')
    {
        ret_val = 1;
    }
    else if(c == 'V')
    {
        ret_val = 5;
    }
    else if(c == 'X')
    {
        ret_val = 10;
    }
    else if(c == 'L')
    {
        ret_val = 50;
    }
    else if(c == 'C')
    {
        ret_val = 100;
    }
    else if(c == 'D')
    {
        ret_val = 500;
    }
    else if(c == 'M')
    {
        ret_val = 1000;
    }
    else
    {
       /* Nop */  
    }
    return ret_val;
}

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

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

int main( void )
{
    string input;
    int answer, prev;
    while ( cin >> input )
    {
        answer = 0;
        prev = 0;

        for ( string ::reverse_iterator it = input.rbegin(); it != input.rend(); it++ )
        {
            int next = convert( *it );
            if ( prev <= next )
            {
                answer += next;
            }
            else
            {
                answer -= next;
            }
            prev = next;
        }

        cout << answer << endl;
    }
    return 0;
}

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

int main(void){
	map <char, int> m;
	int num[] = {1,5,10,50,100,500,1000};
	for (int i=0; i<7; i++)
		m["IVXLCDM"[i]] = num[i];

	char c;
	string r;
	while (cin>>r){
		int tmp, tmp2= m[r[0]],s=0;
		int n=r.size();
		for (int i=0; i<n; i++){
			tmp = m[r[i]];
			if (tmp2<tmp)
				s-= tmp2*2;
			s += tmp;
			tmp2 = tmp;
		}
		cout<<s<<endl;
	}
}

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

int main(){
  vector<char> roman10 = {'I', 'X', 'C', 'M'};
  vector<char> roman5 = {'V', 'L', 'D'};
  vector<int> num10 = {1, 10, 100, 1000};
  vector<int> num5 = {5, 50, 500};

  string S;
  while(cin >> S){
    int ans = 0;

    for(int i=0; i<S.length(); i++){
      bool flag = false;
      for(int j=0; j<3; j++){
        if(S[i] == roman5[j]){
          ans += num5[j]; flag = true; break;
        }
      }
      if(flag) continue;

      for(int j=0; j<4; j++){
        if(S[i] == roman10[j]){
          if(j != 3 && S[i+1] == roman10[j+1]){
            ans += num10[j+1]-num10[j]; i++; break;
          } else if (j != 3 && S[i+1] == roman5[j]){
            ans += num5[j]-num10[j]; i++; break;
          } else {
            ans += num10[j]; break;
          }
        }
      }
    }

    cout << ans << endl;
  }
}

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

using namespace std;

int vle[512] = {0};

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

	string str;
	while(cin >> str, !cin.eof()){
		
		int sum = 0, tmp = 0, befv = 0;
		char befc = 0;
		
		for(int i=0; i<str.size(); ++i){
			
			char nowc = str[i];
			int nowv = vle[nowc];

			if(nowv < befv){
				befc = nowc;
				sum += tmp;
				tmp = befv = nowv;
			}
			else if(nowv == befv){
				tmp += befv;
			}
			else{
				befc = nowc;
				sum -= tmp;
				tmp = befv = nowv;
			}
		}
		
		sum += tmp;
		cout << sum << endl;

	}

	return 0;
}

C++: #include<stdio.h>

int main(){
char ch,;
int sum;
int w,b,a;
sum=0;ch='\0';w=0;b=0;a=0;
while(scanf("%c",&ch)!=EOF){
while(1){
if(ch=='\0')break;
if(ch=='I')w=1;
else if(ch=='V')w=5;
else if(ch=='X')w=10;
else if(ch=='L')w=50;
else if(ch=='C)w=100;
else if(ch=='D')w=500;
else if(ch=='M')w=1000;
switch(w){
case 1:
a=1;break;
case 5:
if(b==1)a=4;else a=5;break;
case 10:
if(b==1)a=9;else a=10;break;
case 50:
if(b==10)a=40;else a=50;break;
case 100:
if(b==10)a=90;else a=100;break;
case 500:
if(b==100)a=400;else a=500;break;
case 1000:
if(b==100)a=9;else a=1000;break;
}
sum+=a;b=a;
}
printf( "%d\n",sum);
sum=0;ch='\0';w=0;b=0;a=0;
}
return 0;
}

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

using namespace std;
map<char, int> roman;

void init() {
    roman['I'] = 1    ;
    roman['V'] = 5    ;
    roman['X'] = 10   ;
    roman['L'] = 50   ;
    roman['C'] = 100  ;
    roman['D'] = 500  ;
    roman['M'] = 1000 ;
}

int to_alnum(const string &s) {
    int alnum = 0;

    int i;
    for (i = 0; i < s.size()-1; i++) {
        if (roman[s[i]] < roman[s[i+1]]) {
            alnum += roman[s[i+1]] - roman[s[i]];
            i++;
        } else {
            alnum += roman[s[i]];
        }
    }

    if (i != s.size()) {
        alnum += roman[s[s.size()-1]];
    }

    return alnum;
}
int main() {
    string s;
    init();
    while (cin >> s) {
        cout << to_alnum(s) << endl;
    }
    return 0;
}

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

using namespace std;

int main(void){

	string roman;
	string fig("IVXLCDM");
	int ure[]={1,5,10,50,100,500,1000};
	int sum;
	while(cin>>roman){
		sum=0;
		for(int i=1;i<roman.length();i++){
			if(ure[fig.find(roman[i])]>ure[fig.find(roman[i-1])]) sum+=-1*ure[fig.find(roman[i-1])];
			else sum+=ure[fig.find(roman[i-1])];
		}
		sum+=ure[fig.find(roman[roman.length()-1])];
		cout<<sum<<endl;
	}

	return 0;
}