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 <cstdio>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

map<char, int> mp;

int getArab(string rm) {
    int total = 0;
    int prev = 0;
    REP(i,rm.size()) {
        int crt = mp[rm[i]];
        if (crt <= prev) {
            total += crt;
        }else {
            total += -2 * prev + crt;        }
        prev = crt;
    }
    return total;
}

int main() {
    mp['I'] = 1;
    mp['V'] = 5;
    mp['X'] = 10;
    mp['L'] = 50;
    mp['C'] = 100;
    mp['D'] = 500;
    mp['M'] = 1000;
    string s;
    while(cin >> s) {
        cout << getArab(s) << endl;
    }
    return 0;
}

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

main(){
  int i,j,min[3],ans;
  char a[102];
  while(cin >> a){
    ans = 0;
    for(i=0;i<3;i++) min[i] = 0;

    for(i=0;i<102;i++){
      if(a[i] == '\0') break;
      else if(a[i] == 'I'){
	min[0]++;
	ans++;
      }
      else if(a[i] == 'V'){
	ans += 5;
	if(min[0] != 0){
	  ans -= min[0] * 2;
	  min[0] = 0;
	}
      }
      else if(a[i] == 'X'){
	ans += 10;
	if(min[0] != 0){
	  ans -= min[0] * 2;
	  min[0] = 0;
	}
	min[1]++;
      }
      else if(a[i] == 'L'){
	ans += 50;
	if(min[1] != 0){
	  ans -= min[1] * 20;
	  min[1] = 0;
	}
      }
      else if(a[i] == 'C'){
	ans += 100;
	if(min[1] != 0){
	  ans -= min[1] * 20;
	  min[1] = 0;
	}
	min[2]++;
      }
      else if(a[i] == 'D'){
	ans += 500;
	if(min[2] != 0){
	  ans -= min[2] * 200;
	  min[2] = 0;
	}
      }
     else if(a[i] == 'M'){
	ans += 1000;
	if(min[2] != 0){
	  ans -= min[2] * 200;
	  min[2] = 0;
	}
      }
    }

    cout << ans << endl;
  }

  return 0;
}

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

using namespace std;

int main() {

	int n;
	char s[64];

	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 <stdio.h>
#include <string.h>

int main(void){
	int map[255];
	map['I'] = 1;
	map['V'] = 5;
	map['X'] = 10;
	map['L'] = 50;
	map['C'] = 100;
	map['D'] = 500;
	map['M'] = 1000;
	int sum = 0;
	char in[101];
	int len;

	while(scanf("%s", in) != EOF){
		len = strlen(in);
		int i = 0;
		sum = 0;
		for(i=0; i<len-1; ++i){
			if(map[in[i]] < map[in[i+1]]){
				sum += map[in[i+1]] - map[in[i]];
				i++;
			}else{
				sum += map[in[i]];
			}
		}
		if(i<len){ sum += map[in[i]]; }
		printf("%d\n", sum);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

// I: 1 V: 5 X: 10 L: 50 C: 100 D: 500 M: 1000

#define PI 4*atan(1);

int n[100] = {0};

void Convert(char s[]){
  for(int i = 0; s[i] != '\0'; i++){
    if(s[i] == 'I')n[i] = 1;
    if(s[i] == 'V')n[i] = 5;
    if(s[i] == 'X')n[i] = 10;
    if(s[i] == 'L')n[i] = 50;
    if(s[i] == 'C')n[i] = 100;
    if(s[i] == 'D')n[i] = 500;
    if(s[i] == 'M')n[i] = 1000;
  }
}

void clear(void) {
  for(int i = 0; n[i] != 0; i++)n[i] = 0;
}

int main(){
  char s[101];
  while(cin >> s){
    clear();
    int sum = 0;
    Convert(s);
    for(int i = 0; n[i] != 0; i++){
      if(n[i] < n[i + 1]){
        sum -= n[i];
      }
      if(n[i] >= n[i + 1]){
        sum += n[i];
      }
    }
    cout << sum << endl;
  }
}

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

int main(void) {
    map<char, int> roman;
    //ローマ文字について情報をmapに入れておく
    roman.insert(make_pair('I', 1)); roman.insert(make_pair('V', 5));
    roman.insert(make_pair('X', 10)); roman.insert(make_pair('L', 50));
    roman.insert(make_pair('C', 100)); roman.insert(make_pair('D', 500));
    roman.insert(make_pair('M', 1000));
    string input;
    while(cin >> input) {
        int sum = roman[input[0]];
        for(int r = 1; r < input.length(); r++) {
            if(roman[input[r]] > roman[input[r - 1]]) sum += roman[input[r]] - 2*(roman[input[r - 1]]);
            else                                      sum += roman[input[r]];
        }
        cout << sum << endl;
    }
    return(0);
}

C++: #include <iostream>
#include <string>
#include <map>
#include <string.h>
#include <cstring>
using namespace std;
int main(){
  map<char,int> ch;//文字の数字辞書登録
  ch['I']=1;
  ch['V']=5;
  ch['X']=10;
  ch['C']=100;
  ch['D']=500;
  ch['M']=1000;
  
  int ans=0;
  int len=0;
  char s[1111];
  while(cin >> s){
    len=strlen(s);
    for(int i=0;i<len;i++){
      if(ch[s[i]]<ch[s[i+1]]){//もしも引き算をすべき場合だったら
	ans-=ch[s[i]];
      }else{
	ans+=ch[s[i]];
      }
    }
    cout << ans << endl;
    ans=0;
  }
}

C++: #include <string.h>
#include <cmath>
#include <stdio.h>

char c[200];

int main(){
	int ans;
	int n;
	while(scanf("%s",&c) != EOF){
		n = strlen(c);
		ans = 0;
		for(int i = 0; i < n; i++){
			if(c[i] == 'I'){
				if(c[i + 1] == 'V' || c[i + 1] == 'X' || c[i + 1] == 'L' || c[i + 1] == 'C' || c[i + 1] == 'D' || c[i + 1] == 'M'){
					ans -= 1;
				}else{
					ans += 1;
				}
			}
			if(c[i] == 'V'){
				if(c[i + 1] == 'X' || c[i + 1] == 'L' || c[i + 1] == 'C' || c[i + 1] == 'D' || c[i + 1] == 'M'){
					ans -= 5;
				}else{
					ans += 5;
				}
			}
			if(c[i] == 'X'){
				if(c[i + 1] == 'L' || c[i + 1] == 'C' || c[i + 1] == 'D' || c[i + 1] == 'M'){
					ans -= 10;
				}else{
					ans += 10;
				}
			}
			if(c[i] == 'L'){
				if(c[i + 1] == 'C' || c[i + 1] == 'D' || c[i + 1] == 'M'){
					ans -= 50;
				}else{
					ans += 50;
				}
			}
			if(c[i] == 'C'){
				if(c[i + 1] == 'D' || c[i + 1] == 'M'){
					ans -= 100;
				}else{
					ans += 100;
				}
			}
			if(c[i] == 'D'){
				if(c[i + 1] == 'M'){
					ans -= 500;
				}else{
					ans += 500;
				}
			}
			if(c[i] == 'M'){
				ans += 1000;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}