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

int main(void){
	string str;
	map<string, int> num;
	num.insert( map<string,int>::value_type("I",1));
	num.insert( map<string,int>::value_type("II",2));
	num.insert( map<string,int>::value_type("III",3));
	num.insert( map<string,int>::value_type("IV",4));
	num.insert( map<string,int>::value_type("V",5));
	num.insert( map<string,int>::value_type("VI",6));
	num.insert( map<string,int>::value_type("VII",7));
	num.insert( map<string,int>::value_type("VIII",8));
	num.insert( map<string,int>::value_type("IX",9));
	num.insert( map<string,int>::value_type("X",10));
	num.insert( map<string,int>::value_type("XI",11));
	num.insert( map<string,int>::value_type("XII",12));
	num.insert( map<string,int>::value_type("XIII",13));
	num.insert( map<string,int>::value_type("XIV",14));
	num.insert( map<string,int>::value_type("XV",15));
	num.insert( map<string,int>::value_type("XVI",16));
	num.insert( map<string,int>::value_type("XVII",17));
	num.insert( map<string,int>::value_type("XVIII",18));
	num.insert( map<string,int>::value_type("XIX",19));
	num.insert( map<string,int>::value_type("XX",20));
	num.insert( map<string,int>::value_type("XXX",30));
	num.insert( map<string,int>::value_type("XL",40));
	num.insert( map<string,int>::value_type("L",50));
	num.insert( map<string,int>::value_type("LX",60));
	num.insert( map<string,int>::value_type("LXX",70));
	num.insert( map<string,int>::value_type("LXXX",80));
	num.insert( map<string,int>::value_type("XC",90));
	num.insert( map<string,int>::value_type("C",100));
	num.insert( map<string,int>::value_type("D",500));
	num.insert( map<string,int>::value_type("M",1000));
	while(cin >> str){
		int ans=0;
		string s;
		for(int i=0;i<str.size();i++){
			string ss=s;
			s+=str[i];
			if(num[s]==0){
				if(num[ss]>0){
					ans+=num[ss];
					s=str[i];
				}
			}
			if(i==str.size()-1){
				ans+=num[s];
			}
		}
		printf("%d\n",ans);
	}
    return 0;
}

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

int num[128];

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

  string s;
  while(cin >> s) {
    reverse(s.begin(), s.end());
    int res = 0;
    for(int i = 0; i < s.size(); ++i) {
      if(i && num[s[i-1]] > num[s[i]]) {
	res -= num[s[i]];
      } else {
	res += num[s[i]];
      }
    }
    cout << res << endl;
  }
  return 0;
}

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

int num(char ch) {
  if(ch=='I') return 1;
  if(ch=='V') return 5;
  if(ch=='X') return 10;
  if(ch=='L') return 50;
  if(ch=='C') return 100;
  if(ch=='D') return 500;
  if(ch=='M') return 1000;
}

int main() {
  string s;
  while(cin >> s) {
    int n=0,y=0;
    for(int i=s.size()-1; i>=0; i--) {
      int x=num(s[i]);
      if(x<y) n-=x;
      else {
	n+=x;
	y=x;
      }
    }
    cout << n << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<map>
using namespace std;
string str;
int sum,size;
map <char,int> t;
int main(){
	t['I']=1;
	t['V']=5;
	t['X']=10;
	t['L']=50;
	t['C']=100;
	t['D']=500;
	t['M']=1000;
	while(cin>>str){
		size=str.size();
		sum=0;
		for(int i=0;i<size-1;i++){
			if(t[str[i]]<t[str[i+1]])sum-=t[str[i]];
			else sum+=t[str[i]];
		}
		cout<<sum+t[str[size-1]]<<endl;
	}
}

C++: #include <iostream>
#include <cstdlib>
using namespace std;
 
int main() {
  string str;
  int size,count = 1,ans = 0,xx[100] = {0};
  char x[100];
  while(cin >> str) {
    char x[100] = {' '};
    int xx[100] = {0};
    size = str.size();
    for(int i=0;i<size;i++) {
      x[i] = *str.substr(i,1).c_str();
      if(x[i] == 'I') {
        xx[i] = 1;
      }
      else if(x[i] == 'V') {
        xx[i] = 5;
      }
      else if(x[i] == 'X') {
        xx[i] = 10;
      }
      else if(x[i] == 'L') {
        xx[i] = 50;
      }
      else if(x[i] == 'C') {
        xx[i] = 100;
      }
      else if(x[i] == 'D') {
        xx[i] = 500;
      }
      else if(x[i] == 'M') {
        xx[i] = 1000;
      }
    }
 
    for(int i=0;i<size-1;i++) {
      if(xx[i] >= xx[i+1]) {
        ans += xx[i];
        if(i == size-2) {
          ans += xx[i+1];
        }
      }
      else if(xx[i] < xx[i+1]) {
        ans -= xx[i];
 
        if(i == size-2) {
          ans += xx[i+1];
        }
      }
    }
    if(size == 1) {
      ans += xx[0];
        }
    cout << ans << endl;
    ans = 0;
  }
}

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

using namespace std;


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

int main(){
	string S;
	map<char,int> m={{'I',1},{'V',5},{'X',10},{'L',50},{'C',100},{'D',500},{'M',1000}};
	while (cin>>S){
		int ans=0;
		REP(i,S.length()-1){
			if (m[S[i]]>=m[S[i+1]]){
				ans+=m[S[i]];
			}else{
				ans-=m[S[i]];
			}
		}
		ans+=m[S[S.length()-1]];
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

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

int main(void){
    string ro;
    int m[256]={};
    m['I']=1,
        m['V']=5,
        m['X']=10,
        m['L']=50,
        m['C']=100,
        m['D']=500,
        m['M']=1000;
    while(cin>>ro){
        int n=0;
        for(auto c:ro)n+=m[c];
        rep(i,ro.size()) if(m[ro[i]]<m[ro[i+1]])n-=2*m[ro[i]];
        cout<<n<<endl;
    }
}

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


int changeTheChar(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 if(c=='M'){
    return 1000;
  }

  

  return 0;

}

int main()
{

  while(true){

    string str;
    cin >> str;

    vector<int> roman(str.size(), 0);
    // ????????????
    for(int i=0;i<str.size();i++){
      roman[i] = changeTheChar(str[i]);
    }

    for(int i=0;i<roman.size();i++){
      // cout << roman[i] << " ";
    }

    int res = 0;
    while(roman.size()>0){
      int maxI=0;
      int maxIndex;
      // ?????§???????´¢
      for(int i=roman.size()-1;i>=0;i--){
	if(maxI <= roman[i]){
	  maxI = roman[i];
	  maxIndex = i;
	}
      }
      // cout << maxIndex << endl;
      // cout << maxI << endl;

      if(maxIndex!=0){
	res += roman[maxIndex] - roman[maxIndex-1];
	roman.erase(roman.begin());
	roman.erase(roman.begin());
      }else{
	res += roman[maxIndex];
	roman.erase(roman.begin());
      }

      // cout << res << endl;
    }

    cout << res << endl;


  }




  return 0;
}

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

using namespace std;

int main(){

	string str;
	char alph[7] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
	int num[7] = {1, 5, 10, 50, 100, 500, 1000};
	int x, y, s[100];
	
	while(cin >> str){
		for(int i=0; i<str.length(); i++){
			for(int j=0; j<7; j++){
				if(str[i] == alph[j]){
					s[i] = num[j];
				}
			}
		}
		
		x = 0;
		y = s[0];
		for(int i=1; i<str.length(); i++){
			if(s[i-1] < s[i]){
				x += s[i] - y;
				y = 0;
			}
			else{
				y += s[i];
			}
		}
		x += y;
		
		cout << x << endl;
		
	}
	
	return 0;
	
}