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

int roman2int(const 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 ans = 0;
    for (unsigned int i = 0; i < s.size()-1; ++i) {
      if (roman2int(s[i]) < roman2int(s[i+1]))
	ans -= roman2int(s[i]);
      else
	ans += roman2int(s[i]);
    }
    cout << ans+roman2int(s[s.size()-1]) << endl;
  }
  return 0;
}

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

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

int main() {
  string str;
  int a, b, l, x;
  char c;
  while (getline(cin, str)) {
    x = 0;
    l = (int)str.size();
    for (int i=0; i<l; i++) {
      c = str.at(i);
      if (c == 'I') a = 1;
      else if (c == 'V') a = 5;
      else if (c == 'X') a = 10;
      else if (c == 'L') a = 50;
      else if (c == 'C') a = 100;
      else if (c == 'D') a = 500;
      else if (c == 'M') a = 1000;
      if (i) {
        if (b >= a) {
          x += b;
        } else {
          x -= b;
        }
      }
      b = a;
    }
    x += b;
    cout << x << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

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

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

  while(cin>>str){
    int nums[str.size()];
    REP(i,str.size())
      nums[i] = roman[str[i]];

    int dec=0;    
    int begin=0;
    int i=0;
    while(i<str.size()-1){
      if(nums[i] < nums[i+1]){
	for(int j=begin; j<=i; j++){
	  dec += nums[j];
	  nums[j] = 0;
	}
	begin = i+2;
      }
      i++;
    }

    int res=0;
    REP(i,str.size()) res += nums[i];

    cout << res-dec << endl;
  }

  return 0;
}

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

int tbl[128];

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

	string s;
	while(getline(cin, s)){
		s += '$';
		int u = 0;
		for(int i = 0; i + 1 < s.size(); ++i){
			if(tbl[s[i]] < tbl[s[i+1]]){
				u -= tbl[s[i]];
			}
			else{
				u += tbl[s[i]];
			}
		}
		cout << u << '\n';
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		int b[2][100000]={0};bool bb[2][100000]={0};
		for(int i=0;i<100000;i++)for(int j=0;j<2;j++)b[j][i]=0;
		for(int i=0;i<100000;i++)for(int j=0;j<2;j++)bb[j][i]=0;
		int a[200],sum=0;
	    for(int i=0;i<200;i++)a[i]=0;
		for(int i=0;i<s.size();i++){
			int t;
			if(s[i]=='I')t=1;
			if(s[i]=='V')t=5;
			if(s[i]=='X')t=10;
			if(s[i]=='L')t=50;
			if(s[i]=='C')t=100;
			if(s[i]=='D')t=500;
			if(s[i]=='M')t=1000;
			a[i]=t;
			if(i&&a[i]!=a[i-1]&&b[0][a[i]])b[1][t]++;
			else b[0][t]++;
		}
		for(int i=s.size()-1;i>=0;i--){
			if(sum<a[i]){
				if(i!=s.size()-1&&a[i]!=a[i+1]&&bb[0][a[i]]){
					sum-=b[1][a[i]]*a[i];
				    i-=b[1][a[i]]-1;
				}
				else{sum+=b[0][a[i]]*a[i];
				i-=b[0][a[i]]-1;bb[0][a[i]]=1;}
			}		
			else{
				sum-=b[0][a[i]]*a[i];
				    i-=b[0][a[i]]-1;
				    bb[0][a[i]]=1;
			}
		}
		cout<<sum<<endl;
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>

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

#define I 1
#define V 5
#define X 10
#define L 50
#define C 100
#define D 500
#define M 1000

using namespace std;

int main(){

	string str;
	while(cin>>str){
		int data[200];
		int sum = 0;
		
		//データの数値化
		for(int i=0;i<str.size();i++){
			switch(str[i]){
				case 'I':
					data[i]=I;
					break;
				case 'V':
					data[i]=V;
					break;
				case 'X':
					data[i]=X;
					break;
				case 'L':
					data[i]=L;
					break;
				case 'C':
					data[i]=C;
					break;
				case 'D':
					data[i]=D;
					break;
				case 'M':
					data[i]=M;
					break;
			}
		}

		for(int i=0;i<str.size();i++){
			if(i==str.size()-1){
				sum+=data[i];
			}
			else{
				if(data[i]<data[i+1]){
					sum+= (data[i+1]-data[i]);
					i++;
				}
				else{
					sum+=data[i];
				}
			}
		}

		cout<<sum<<endl;
	}

	return 0;

}

/*
IV
CCCCLXXXXVIIII
CDXCIX
*/

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

int main(){
	string s;
	while(cin >> s){
		char b[s.size()];
		for(int i=0;i<s.size();i++) b[i] = s[i];
		int k[3] = {1,1,1};
		for(int i=0;i<s.length()-1;i++){
			if(b[i]=='I' and (b[i+1]=='X' or b[i+1]=='V')) k[0] = -1;
			if(b[i]=='X' and (b[i+1]=='L' or b[i+1]=='C')) k[1] = -1;
			if(b[i]=='C' and (b[i+1]=='D' or b[i+1]=='M')) k[2] = -1;
		}
		bool cs = false;
		bool ce = false;
		bool xs = false;
		bool xe = false;
		int w = 0;
		for(int i=0;i<s.length();i++){
			int a;
			if(b[i]=='M') a = 1000;
			if(b[i]=='D') a = 500;
			if(b[i]=='C'){
				if(ce) a = 100*k[2];
				else   a = 100;
				if(not cs) cs = true;
			}
			else if(cs) ce = true;
			if(b[i]=='L') a = 50;
			if(b[i]=='X'){
				if(xe) a = 10*k[1];
				else   a = 10;
				if(not xs) xs = true;
			}
			else if(xs) xe = true;
			if(b[i]=='V') a = 5;
			if(b[i]=='I') a = k[0];
			w += a;
		}
		cout << w << endl;
	}
}

C++: #include <string>
#include <iostream>
using namespace std;
int a[100]; string s;
int main() {
	while(cin >> s) {
		int n = s.size();
		for(int i = 0; i < n; i++) {
			switch(s[i]) {
				case 'I': a[i] = 1; break;
				case 'V': a[i] = 5; break;
				case 'X': a[i] = 10; break;
				case 'L': a[i] = 50; break;
				case 'C': a[i] = 100; break;
				case 'D': a[i] = 500; break;
				case 'M': a[i] = 1000; break;
			}
		}
		int ret = 0;
		for(int i = 0; i < n - 1; i++) {
			if(a[i] >= a[i + 1]) ret += a[i];
			else ret -= a[i];
		}
		printf("%d\n", ret);
	}
	return 0;
}