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 <stdio.h>

int main(){
	char str[100];
	int num,i;
	while(scanf("%s",str) != EOF){
		num = 0;
		for(i = 0;str[i] != 0;i++){
			switch(str[i]){
				case 'I':
				if(str[i + 1] == 'V' || str[i + 1] == 'X') num--;
				else num++;
				break;
				case 'V':
				num += 5;
				break;
				case 'X':
				if(str[i + 1] == 'L' || str[i + 1] == 'C') num -= 10;
				else num += 10;
				break;
				case 'L':
				num += 50;
				break;
				case 'C':
				if(str[i + 1] == 'D' || str[i + 1] == 'M') num -= 100;
				else num += 100;
				break;
				case 'D':
				num += 500;
				break;
				case 'M':
				num += 1000;
				break;
			}
		}
		printf("%d\n",num);
	}
	return 0;
}

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

const char i = 'I', v = 'V', x = 'X', l = 'L', c = 'C', d = 'D', m = 'M';

int number(char s)
{
     switch (s) {
     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;
     while (cin >> str) {
          int i = 0;
          int ans = 0;
          while (i < str.size()) {
               int tmp = 0;
               char s = str[i];
               while (s == str[i] && i < str.size()) {
                    tmp += number(s);
                    i++;
               }
               if (number(s) < number(str[i])) ans -= tmp;
               else ans += tmp;
          }
          cout << ans << endl;
     }

     return 0;
}

C++: #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'){
					ans -= 1;
				}else{
					ans += 1;
				}
			}
			if(c[i] == 'X'){
				if(c[i + 1] == 'L' || c[i + 1] == 'C'){
					ans -= 10;
				}else{
					ans += 10;
				}
			}
			if(c[i] == 'C'){
				if(c[i + 1] == 'D' || c[i + 1] == 'M'){
					ans -= 100;
				}else{
					ans += 100;
				}
			}
			if(c[i] == 'V'){
				ans += 5;
			}
			if(c[i] == 'L'){
				ans += 50;
			}
			if(c[i] == 'D'){
				ans += 500;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
int main()
{
	char s[101];
	int t[101],l[100],i,j,r;
	l['I']=1;
	l['V']=5;
	l['X']=10;
	l['L']=50;
	l['C']=100;
	l['D']=500;
	l['M']=1000;
	for(;gets(s);)
	{
		memset(t,0,sizeof(t));
		t[0]=l[s[0]];
		for(i=1,j=0;s[i];i++)
		{
			if(s[i]==s[i-1])
				t[j]+=l[s[i]];
			else
			{
				if(l[s[i]]>l[s[i-1]])
					t[j]*=-1;
				t[++j]+=l[s[i]];
			}
		}
		for(i=r=0;i<=j;i++)
			r+=t[i];
		printf("%d\n",r);
	}
	return 0;
}

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

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

int getNum(char c){
  const string R="IVXLCDM";
  const int N[]={1,5,10,50,100,500,1000};
  for(int i=0;i<R.size();++i){
    if(R[i]==c) return N[i];
  }
  return 0;
}

int main(void){
  string s;
  while(cin>>s){
    int ans=0,back=1001;
    for(int i=0,a;i<s.size();++i){
      a=getNum(s[i]);
      ans=(a>back)?ans-back*2+a:ans+a;
      back=a;
    }
    cout<<ans<<endl;
  }
}

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

int main() {
    string s;

    while (getline(cin, s)) {
        int sum = 0;
        vector<int> arr(s.length());

        for (int i = 0; i < s.length(); i++) {
            if (s.at(i) == 'I') {
                arr.at(i) = 1;
            }
            else if (s.at(i) == 'V') {
                arr.at(i) = 5;
            }
            else if (s.at(i) == 'X') {
                arr.at(i) = 10;
            }
            else if (s.at(i) == 'L') {
                arr.at(i) = 50;
            }
            else if (s.at(i) == 'C') {
                arr.at(i) = 100;
            }
            else if (s.at(i) == 'D') {
                arr.at(i) = 500;
            }
            else if (s.at(i) == 'M') {
                arr.at(i) = 1000;
            }
        } //end for

        for (int j = arr.size()-1; j >=0;j--) {
            if (j == arr.size() - 1) {
                sum += arr.at(j);
            }
            else if (arr.at(j) < arr.at(j + 1)) {
                sum -= arr.at(j);
            }
            else {
                sum += arr.at(j);
            }
        }
        cout << sum << endl;
    }
}

C++: //0039 Roman Figure

#include<iostream>
#include<string>
#include<map>
using namespace std;

int main(void)
{
	string str;
	while(cin >> str)
	{
		int s = 0;
		for(int i = 0; i < str.size(); i++)
		{
			char c = str[i];
			char next = (i==str.size()-1 ? 0 : str[i+1]);
			switch(c)
			{
			case 'I': 
				if(next == 'V') s += 4, i++;
				else if(next == 'X') s += 9, i++;
				else s+=1;
				break;
			case 'V':
				s += 5;
				break;
			case 'X':
				if(next == 'L') s += 40, i++;
				else if(next== 'C') s += 90, i++;
				else s+=10;
				break;
			case 'L':
				s += 50;
				break;
			case 'C':
				if(next == 'D') s += 400, i++;
				else if(next =='M') s += 900, i++;
				else s += 100;
				break;
			case 'D':
				s += 500;
				break;
			case 'M':
				s += 1000;
				break;
			}
		}
		cout << s << endl;
	}
	return 0;
}

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) {
    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]) {
	count++;
	if(i == size-2) {
	  ans += xx[i+1] * count;
	  count = 1;
	}
      }
      else {
	if(xx[i] < xx[i+1]) {
	  ans -= xx[i] * count;
	  count = 1;
	}
	else if(xx[i] > xx[i+1]) {
	  ans += xx[i] * count;
	  count = 1;
	}
	if(i == size-2) {
	  ans += xx[i+1];
	  count = 1;
	} 
      }
    }
    cout << ans << endl;
    ans = 0;
  }
}