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 <cstdio>
#include <map>
#include <string>

using namespace std;

int main()
{
	map <string, int> list;
	
	list["I"] = 1;
	list["V"] = 5;
	list["X"] = 10;
	list["L"] = 50;
	list["C"] = 100;
	list["D"] = 500;
	list["M"] = 1000;
	list["N"] = 0;
		
	char s[10001];
	while(scanf("%s", s) != EOF){
		string str = s;
		string str_next = s;
		
		int len = str.size();
		int sum = 0;
		
		
		for(int i = 0; i < len; i++){
			str = s[i];
			str_next = s[i+1];
			
			if(list[str] < list[str_next]){
				sum += list[str_next] - list[str];
				i++;
			}
			
			else sum += list[str];
		}
		
		printf("%d\n", sum);
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;
typedef vector <string> vs;

int main(void){
	vi x;
	string suit = "IVXLCDM";
	int num[] = {1,5,10,50,100,500,1000};
	while (true){
		string roman;
		cin>>roman;
		if (cin.eof()) break;
		int tmp, tmp2=9999;
		for (int i=0; i<(int)roman.size(); i++)
			for (int j=0; j<(int)suit.size(); j++)
				if (roman[i]==suit[j]){
					tmp = num[j];
					if (i!=0 && tmp2<tmp)
						x[i-1] = -tmp2;
					x.push_back(tmp);
					tmp2 = tmp;
					break;
				}
		int s=0;
		for (int i=0; i<(int)x.size(); i++)
			s += x[i];
		cout<<s<<endl;
		x.clear();
	}
}

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

int main(){
	string s;
	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;
	while( cin >> s ){
		int sum = 0;
		
		while( !s.empty() ){
			for(unsigned int i=0 ; i<s.size() ; i++){
				if( i!=s.size()-1 && m[ s[i] ] < m[ s[i+1] ] ){
					sum += m[ s[i+1] ] - m[ s[i] ];
					s.erase(i,2);
					break;
				}else{
					sum += m[ s[i] ];
					s.erase(i,1);
					break;
				}
			}
		}
		cout << sum << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
char ta[]={'I','V','X','L','C','D','M'};
int t[]={1,5,10,50,100,500,1000};
int main(){
	string n;
	while(cin>>n){
	bool used[5000]={0};
	int ans=0,a=0,b=0;
		
		for(int i=1;i<n.size();i++){
			for(int j=0;j<7;j++)if(n[i]==ta[j])a=t[j];
			for(int j=0;j<7;j++)if(n[i-1]==ta[j])b=t[j];
			if(b<a){
			used[i]=used[i-1]=1;
			ans+=a-b;
			}
		}
			for(int i=0;i<n.size();i++){
			for(int j=0;j<7;j++)if(n[i]==ta[j])a=t[j];
			if(used[i]==0)ans+=a;
			}
		cout<<ans<<endl;
	}
	return 0;
}

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

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

int RomanToNum(string r){
	int num = 0;
	for(int i=0;i<r.size();i++){
		if(i <r.size()-1 && number(r[i])<number(r[i+1])){
			num += number(r[i+1]);
			num -= number(r[i]);
			i++;
		}
		else{
			num += number(r[i]);
		}
	}
	return num;
}

int main(){
  string roman;
  while(cin >> roman){
		cout << RomanToNum(roman) << endl;
  }
  return 0;
}

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

using namespace std;

int getvalue(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 -1;
}

int parseStr(string str){
  int ret=0;
  int now;
  int next;

  for(int i=0;i<str.size();i++){
	now = getvalue(str[i]);
	if(i != str.size() - 1){
	  next = getvalue(str[i+1]);
	}else{
	  next = -1;
	}
	
	if(now >= next){
	  ret += now;
	}else{
	  ret += next - now;
	  i++;
	}
  }
  return ret;
}

int main(void){
  string tmp;

  while(cin >> tmp){
	cout << parseStr(tmp) << endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string S; char T[8] = "IVXLCDM"; int X[7] = { 1,5,10,50,100,500,1000 }, l[10000];
int main() {
	while (cin >> S) {
		int cnt = 0;
		for (int i = 0; i < S.size(); i++) {
			for (int j = 0; j < 7;j++){
				if (S[i] == T[j]) { l[i] = j; cnt += X[j]; }
			}
		}
		for (int i = 1; i < S.size(); i++) {
			if (l[i - 1] > l[i]) { cnt -= X[l[i - 1]]; }
		}
		cout << cnt << endl;
	}
}

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

int ch(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 main()
{
	string s;
	int a,ans;
	while(cin >> s){
		a=0;
		ans=0;
		for(int i=s.size()-1;i>=0;--i){
			if(a>ch(s[i])){
				ans-=ch(s[i]);
			}else {
				ans += ch(s[i]);
			}
			a=ch(s[i]);
		}
		cout << ans << endl;
	}
}

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

const char roma[7] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
const int cost[7] = {1, 5, 10, 50, 100, 500, 1000};

int main(){
	std::string str;
	while(std::cin >> str){
		int res = 0;

		for(int i = 0; i < str.size(); i++){
			int a = 0, b = 0;
			a = std::find(roma, roma + 7, str[i]) - roma;

			if(i == str.size() - 1)res += cost[a];
			else {			
				b = std::find(roma, roma + 7, str[i + 1]) - roma;
				if(a == b)res += cost[a];
				else if(a > b)res += (cost[a] + cost[b]), i++;
				else if(a < b)res += (cost[b] - cost[a]), i++;
			}
		}

		std::cout << res << std::endl;
	}
	return 0;
}

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

int main(){
	string s;
	while ( cin >> s ){
		s += '0';
		int size = s.size();
		int* arabian = new int[ size ];

		for ( int i = 0; i < size; ++i ){
			switch( s[ i ] ){
				case 'I' : arabian[ i ] = 1; break;
				case 'V' : arabian[ i ] = 5; break;
				case 'X' : arabian[ i ] = 10; break;
				case 'L' : arabian[ i ] = 50; break;
				case 'C' : arabian[ i ] = 100; break;
				case 'D' : arabian[ i ] = 500; break;
				case 'M' : arabian[ i ] = 1000; break;
				default : arabian[ i ] = 0;break;
			}
		}

		int figure = 0;
		for ( int i = 0; i < size-1; ++i ){
			if ( arabian[ i ] < arabian[ i + 1 ] ){
				arabian[ i ] = -arabian[ i ];
			}
			figure += arabian[ i ];
		}

		cout << figure << endl;

		delete[] arabian;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int value[128];

void init() {
	value['I'] = 1;
	value['V'] = 5;
	value['X'] = 10;
	value['L'] = 50;
	value['C'] = 100;
	value['D'] = 500;
	value['M'] = 1000;
}

int main() {
	init();

	string number;
	while(cin >> number) {
		int res = 0;

		for(unsigned i = 0; i < number.size(); ++i) {
			if(i + 1 < number.size() && value[number[i]] < value[number[i + 1]]) {
				res -= value[number[i]];
			}
			else {
				res += value[number[i]];
			}
		}

		cout << res << endl;
	}

	return EXIT_SUCCESS;
}

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

int main(){
	string s;
	int num[256];
	num['I']=1;
	num['V']=5;
	num['X']=10;
	num['L']=50;
	num['C']=100;
	num['D']=500;
	num['M']=1000;
	while(cin>>s){
		int ans=num[s[0]];
		for(int i=1;i<s.size();i++){
			if(num[s[i-1]]<num[s[i]])ans+=num[s[i]]-2*num[s[i-1]];
			else ans+=num[s[i]];
		}
		cout<<ans<<endl;
	}
	return 0;
}