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 <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()
{
  string str;
  while(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>
#include<cmath>
using namespace std;
int dight(int n){
  return n==0?1:int(log10(n))+1;
}
int dif(int a,int b){
  if(a<b) return b-a;
  else return a+b;
}
int m(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,a[100],count=0;
    a[0] = m(s[0]);
    for(int i=1;i<s.size();i++){
      if(s[i]==s[i-1]) a[count] += m(s[i]);
      else{
	count++;
	a[count] = m(s[i]);
      }
    }
    if(count==0) ans = a[0];
    for(int i=1;i<=count;i++){
      if(a[i-1]>a[i]&&dight(a[i-1])>dight(a[i])){
	ans += a[i-1];
	if(i==count) ans += a[i];
      }
      else{
	ans += dif(a[i-1],a[i]);
	if(i+1==count) ans += a[i];
	i++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  map<char, int> dict = {
    { 'I', 1 },
    { 'V', 5 },
    { 'X', 10 },
    { 'L', 50 },
    { 'C', 100 },
    { 'D', 500 },
    { 'M', 1000 },
  };
  
  string s;
  while (cin >> s) {
    int n = s.size();
    if (n == 1) {
      cout << dict[s[0]] << '\n';
      continue;
    }
    int ans = 0;
    rep(i, n) {
      if (i + 2 <= n) {
        if (dict[s[i]] < dict[s[i + 1]]) {
          ans += dict[s[i + 1]] - dict[s[i]];
          i++;
          continue;
        }
      }
      ans += dict[s[i]];
    }
    cout << ans << '\n';
  }
}

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

using namespace std;

int main(void){
	
	
	vector<int> temp;
	vector<int> num;
	char ruman_num[100];
	int sum;
	
	
	while(scanf("%s",ruman_num)!=EOF){
		sum=0;
		
		for(int i=0;i<100;i++){
			if(ruman_num[i]=='I'){
				num.push_back(1);
			}else if(ruman_num[i]=='V'){
				num.push_back(5);
			}else if(ruman_num[i]=='X'){
				num.push_back(10);
			}else if(ruman_num[i]=='L'){
				num.push_back(50);
			}else if(ruman_num[i]=='C'){
				num.push_back(100);
			}else if(ruman_num[i]=='D'){
				num.push_back(500);
			}else if(ruman_num[i]=='M'){
				num.push_back(1000);
			}
		}
		
		
		for(int i=0;i<(num.size())-1;i++){
			if(num[i]<num[i+1]){
				temp.push_back(num[i+1]-num[i]);
				i++;
			}else{
				temp.push_back(num[i+1]+num[i]);
			}
		}
			
			
		for(int i=0;i<temp.size();i++){
			sum=sum+temp[i];
		}
			
			
		cout<<sum<<endl;
		temp.clear();
		num.clear();
		for(int i=0;i<100;i++){
			ruman_num[i]='0';
		}
	}
	return 0;
}

C++: #include<cstdio>
int main(){
  char s[105];
  int sum,i,a[105];
  while(scanf("%s",s)!=EOF){
    sum = 0;
    for(i=0;s[i]!='\0';i++){
      if(s[i] == 'M') a[i] = 1000;
      if(s[i] == 'D') a[i] = 500;
      if(s[i] == 'C') a[i] = 100;
      if(s[i] == 'L') a[i] = 50;
      if(s[i] == 'X') a[i] = 10;
      if(s[i] == 'V') a[i] = 5;
      if(s[i] == 'I') a[i] = 1;
      if(i>0) sum += a[i-1]<a[i]?-a[i-1]:a[i-1];
    }
    printf("%d\n",sum+a[i-1]);
  }
  return(0);
}