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 <stdio.h>
#include <string>
using namespace std;
int main(){
	int ans=0;
	char c[100]="";
	string str;
	while(cin>>str){
		for(int i=0;i<str.size();i++){
			c[i]=str[i];
			switch(c[i]){
			case'I':
				ans+=1;
				break;
			case'V':
				if(c[i-1]=='I'){
					ans+=3;
					break;
				}else{
					ans+=5;
					break;
				}
			case'X':
				if(c[i-1]=='I'){
					ans+=8;
					break;
				}else{
					ans+=10;
					break;
				}
			case'L':
				if(c[i-1]=='X'){
					ans+=30;
					break;
				}else{
					ans+=50;
					break;
				}
			case'C':
				if(c[i-1]=='X'){
					ans+=80;
					break;
				}else{
					ans+=100;
					break;
				}
			case'D':
				if(c[i-1]=='C'){
					ans+=300;
					break;
				}else{
					ans+=500;
					break;
				}
			case'M':
				if(c[i-1]=='C'){
					ans+=800;
					break;
				}else{
					ans+=1000;
					break;
				}
			}
		}
		cout<<ans<<endl;
		ans=0;
		int c[100];
	}
	return 0;
}

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

int main(){
  map<char,int> m;
  m['I']=1;
  m['V']=5;
  m['X']=10;
  m['L']=50;
  m['C']=100;
  m['D']=500;
  m['M']=1000;
  m['O']=0;
  string s;
  while(cin>>s){
    int ans=0;
    int n=0;
    char c='O';
    for(string::iterator it=s.begin();it!=s.end();it++){
      if(*it==c) n++;
      else{
	if(m[c]*5==m[*it]||m[c]*10==m[*it]){
	  ans+=m[*it]-m[c]*n;
	  n=0;
	  continue;
	}
	else if(n!=0) ans+=m[c]*n;
	c=*it;
	n=1;
      }
    }
    if(n>1) ans+=m[c]*n;
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
char x[200];
char Roma[7]={'I','V','X','L','C','D','M'};
int Arabia[7]={1,5,10,50,100,500,1000};
int a=0,b,ans=0,ls;
string s;
while(cin>>s){
ans=0;
a=0;
ls=s.size();
for(int i=ls-1;i>-1;i--){
for(int j=0;j<7;j++){
if(s[i]==Roma[j])b=Arabia[j];}
if(b>=a){ans+=b; a=b;}
if(b<a)ans-=b;}
cout<<ans<<endl;}}

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

using namespace std;
 
int c[128];
 
void init(){
    c['I'] = 1;   c['V'] = 5;   c['X'] = 10;   c['L'] = 50; 
    c['C'] = 100; c['D'] = 500; c['M'] = 1000;
}
 
int main(){
    string str;
 
    init();
    while(cin >> str){
	int sum = 0;
	for(int i = 0 ; i < (int)str.size()-1 ; i++){
	    sum += c[str[i]]*((c[str[i]] < c[str[i+1]]) ? -1 : 1);
	}
	sum += c[str[str.size()-1]];
	cout << sum << endl;
    }
    return 0;
}

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

int a(char x){
	switch (x) {
		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;
	}
	return 0;
}
int main(void){
	string str;
	int ans=0;
	int p=0;
	while(cin>>str){
		ans=0;
		p=0;
		for(int i=str.length()-1;i>=0;i--){
			int now=a(str[i]);
			if(p>now)ans-=now;
			else ans+=now;
			p=now;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main()
{
	char rome[110];
  int	num, ara, nu;
	while(cin >> rome){
		num = ara = nu = 0;
		for(int i = 0; rome[i] != '\0'; i++){
			if (rome[i] == 'I') num = 1;
			else if (rome[i] == 'V') num = 5;
			else if (rome[i] == 'X') num = 10;
			else if (rome[i] == 'L') num = 50;
			else if (rome[i] == 'C') num = 100;
			else if (rome[i] == 'D') num = 500;
			else if (rome[i] == 'M') num = 1000;

			if (nu < num)	ara += num - nu - nu;
			else ara += num;
			nu = num;
		}
		cout << ara << endl;
	}
	return (0);
}

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

int main(void){
  char s[104];
	int alpha[256];

	alpha['\0'] = 0;
	alpha['I'] = 1;
	alpha['V'] = 5;
	alpha['X'] = 10;
	alpha['L'] = 50;
	alpha['C'] = 100;
	alpha['D'] = 500;
	alpha['M'] = 1000;

	while(scanf("%s",s) != EOF){
		int sum = 0;
		int len = strlen(s);

		for(int i=0;i<len;i++){
			if(alpha[s[i]] >= alpha[s[i+1]]){
				sum += alpha[s[i]];
			}
			else{
				sum -= alpha[s[i]];
			}
		}
		cout<<sum<<endl;
	}

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
char m[7]={'I','V','X','L','C','D','M'};
int n[7]={1,5,10,50,100,500,1000};
int d[110];
int main(){
	string s;
	while(cin>>s){
		for(int i=0;i<s.size();i++){
			for(int j=0;j<7;j++){
				if(m[j]==s[i])d[i]=n[j];
			}
		}
		int ans=0;
		for(int i=0;i<s.size();i++){
			bool t=false;
			for(int j=i+1;j<s.size();j++){
				if(d[j]>d[i])t=true;
			}
			if(t)ans-=d[i];
			else ans+=d[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}

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


int main(){
  int sum,i,j,kari;
  string data, str;
  while(getline(cin, str)) {
    data = "KKKKKKKKKKKKKKKKKKKKKKKKKKKKK";
    data = data.replace(0, str.length(), str);
    sum = j = 0;
    
    while(data[j] != 'K'){
      if(data[j] == 'M'){
	sum += 1000;
      }else if(data[j] == 'D'){
	if(data[j + 1] == 'M'){
	  sum += 900;
	    j++;
	}else{
	  sum += 500;
	}
      }else if(data[j] == 'C'){
	if(data[j + 1] == 'D' || data[j + 1] == 'M'){
	  if(data[j + 1] == 'D'){
	    sum += 400;
	    j++;
	  }else{
	    sum += 900;
	    j++;
	  }
	}else{
	  sum += 100;
	}
      }else if(data[j] == 'L'){
	sum += 50;
      }else if(data[j] == 'X'){
	if(data[j+1] == 'L' || data[j+1] == 'C'){
	  if(data[j+1] == 'L'){
	    sum += 40;
	    j++;
	  }else{
	    sum += 90;
	    j++;
	  }
	}else{
	  sum += 10;
	}
      }else if(data[j] == 'V'){
	sum += 5;
      }else if(data[j] == 'I'){
	if(data[j + 1] == 'V' || data[j + 1] == 'X'){
	  if(data[j + 1] == 'V'){
	    sum += 4;
	    j++;
	  }else{
	    sum += 9;
	    j++;
	  }
	}
	else{
	  sum += 1;
	}
      }
      j++;
    }
    
    cout << sum << endl;
  }
  
  return 0;
}

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

int rom2int(const 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 rom2int(const std::string s){
    int r = 0;
    for(int i = 0; i < s.size() - 1; i++){
        if(rom2int(s[i]) < rom2int(s[i+1])){
            r -= rom2int(s[i]);
        }
        else{
            r += rom2int(s[i]);
        }
    }
    r += rom2int(s[s.size()-1]);
    return r;
}

int main(){
    std::string s;
    while(std::cin >> s){
        std::cout << rom2int(s) << std::endl;
    }
}

C++: #include <bits/stdc++.h>
int from_roman(const std::string &s){
    std::map<char, int> m = {
        { 'I', 1 },
        { 'V', 5 },
        { 'X', 10 },
        { 'L', 50 },
        { 'C', 100 },
        { 'D', 500 },
        { 'M', 1000 }
    };
    int n=0;
    for(int i = 0; i < (int)s.size(); ++i){
        if(m[s[i]] >= m[s[i+1]]) n += m[s[i]];
        else n -= m[s[i]];
    }
    return n;
}

// int to_roman(int n){
//     std::vector<std::pair<std::string, std::string>> res;
//     while(n){
//         int d = n
//     }
// }

using namespace std;
int main(){
    string n;
    while(cin >> n){
        cout << from_roman(n) << endl;
    }
}