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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){

	string str;

	while(cin>>str){
    int ans=0;
        for(int i=0;;i++){

            if(str[i]=='M')ans+=1000;
            else if(str[i]=='D')ans+=500;
            else if(str[i]=='C'&&str[i+1]=='D')ans+=400,i++;
            else if(str[i]=='C')ans+=100;
            else if(str[i]=='L')ans+=50;
            else if(str[i]=='X'&&str[i+1]=='L')ans+=40,i++;
            else if(str[i]=='X')ans+=10;
            else if(str[i]=='V')ans+=5;
            else if(str[i]=='I'&&str[i+1]=='V')ans+=4,i++;
            else if(str[i]=='I')ans+=1;
            else if(str[i]==0)break;

        }

        cout<<ans<<endl;
        ans=0;

        str="";
	}


	return 0;
}

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

int Num(int a){
	switch(a){
		case 73 : return 1;
		case 86 : return 5;
		case 88 : return 10;
		case 76 : return 50;
		case 67 : return 100;
		case 68 : return 500;
		case 77 : return 1000;
		default : return 0;
	}
}

int main(){
	char str[110];
	int ch1, ch2, sum;
	
	for(int i = 0; i < 110; i++) str[i] = 0;
	
	while((scanf("%s", str)) != EOF){
		sum = 0;
		
		for(int i = 0; str[i] != 0; i++){
			ch1 = Num(str[i]);
			ch2 = Num(str[i + 1]);
			if(ch1 >= ch2) sum += ch1;
			else sum -= ch1;
		}
		
		printf("%d\n", sum);
		
		for(int i = 0; i < 110; i++) str[i] = 0;
	}
	
	return 0;
}

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

using namespace std;

int roma[128];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    roma['I']=1;
    roma['V']=5;
    roma['X']=10;
    roma['L']=50;
    roma['C']=100;
    roma['D']=500;
    roma['M']=1000;
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string str;
    while(getline(cin, str)){
        int ans=roma[(unsigned)str[str.length()-1]];
        for(int i=str.length()-2; i>=0; i--){
            int rn=roma[(unsigned)str[i]];
            if(rn>=roma[(unsigned)str[i+1]]) ans+=rn;
            else ans-=rn;
        }
        cout<<ans<<'\n';
    }
    return 0;
}

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


int itorab(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;
        default:
            break;
    }
}

int main(){
    string str;
    while(cin>>str){
        int n=str.length();
        int ans=0;
        ans += itorab(str[n-1]);
        for(int i=n-1;i>0;i--){
            if(itorab(str[i-1])>=itorab(str[i])){
                ans+=itorab(str[i-1]);
            }else{
                ans-=itorab(str[i-1]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

#define COMP(a, b) ((a) == (b) ? (-a) : (a))

using namespace std;

int main() {
	int pre, cur, ans;
	string str;
	map<char, int> v;
	v['I'] = 1;
	v['V'] = 5;
	v['X'] = 10;
	v['L'] = 50;
	v['C'] = 100;
	v['D'] = 500;
	v['M'] = 1000;

	while (cin >> str) {
		pre = cur = ans = 0;
		for (int i = 0; i < str.size(); i++) {
			cur = v[str[i]];
			switch (cur) {
				case 1:
					ans += pre;
					break;
				case 5:
				case 10:
					ans += COMP(pre, 1);
					break;
				case 50:
				case 100:
					ans += COMP(pre, 10);
					break;
				case 500:
				case 1000:
					ans += COMP(pre, 100);
					break;
			}
			pre = cur;
		}
		ans += pre;
		cout << ans << endl;
	}

	return 0;
}

C++: #include <iostream>

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

int main(){
	std::string s;
	while(std::cin >> s, !std::cin.eof()){
		int res = 0;
		for(int i=0;i<s.length()-1;i++){
			if(rfiguretonum(s[i]) < rfiguretonum(s[i+1]))
				res -= rfiguretonum(s[i]);
			else
				res += rfiguretonum(s[i]);
		}
		res += rfiguretonum(s[s.length()-1]);
		std::cout << res << std::endl;
	}
}

C++: #include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() {
    string s;
    while (getline(cin, s)) {
        int a = 0;
        rep (i, s.size()) {
            if (i+1 < (int)s.size() && val(s[i]) < val(s[i+1])) a -= val(s[i]);
            else a += val(s[i]);
        }
        printf("%d\n", a);
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int serch(char str)
{
    if(str=='I')return 1;
    else if(str=='V')return 5;
    else if(str=='X')return 10;
    else if(str=='L')return 50;
    else if(str=='C')return 100;
    else if(str=='D')return 500;
    else return 1000;
}
int main()
{
    int fron=0,bac=0,sum=0;
    string str;
    while(cin>>str){
        for(int i=0;str[i]!='\0';i++){
            bac=serch(str[i]);
            if(fron>=bac)sum+=bac;
            else sum+=bac-fron*2;
            fron=bac;
            bac=0;
        }
        cout<<sum<<endl;
        sum=0;fron=0;
    }
}

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

using namespace std;

int main(void){

  string s;
  while( cin >> s ){

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

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

    int sum = 0;
    for( int i = 0 ; i < s.size() ; i++ ){
      if( i + 1 == s.size() )break;
      if( t[i] < t[i+1] ){
	sum = sum + t[i+1] - t[i];
	t[i+1] = t[i] = 0;
	i++;
      }
      else {
	sum += t[i];
	t[i] = 0;
      }
    }
    sum += t[s.size()-1];
    cout << sum << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<cstring>
using namespace std;
int main(void)
{
	char buf[101];
	int i,j,suu[100],x,len,sum;
	while(scanf("%s",buf)!=EOF)	{
		len=strlen(buf);
		for(i=0;i<len;i++)	{
			if(buf[i]=='I')	suu[i]=1;
			if(buf[i]=='V')	suu[i]=5;
			if(buf[i]=='X')	suu[i]=10;
			if(buf[i]=='L')	suu[i]=50;
			if(buf[i]=='C')	suu[i]=100;
			if(buf[i]=='D')	suu[i]=500;
			if(buf[i]=='M')	suu[i]=1000;
		}
		sum=0;
		for(i=0;i<len-1;i++)	{
			if(suu[i]<suu[i+1])	{
				sum-=suu[i];
			}
			else {
				sum+=suu[i];
			}
		}
		sum+=suu[len-1];
		printf("%d\n",sum);
	}
	return 0;
}