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>
#include<string.h>

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

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   string s;
   while(cin>>s)
   {
     int sum=0;
     for(int i=0;i<s.length();i++)
     {
       if(s[i]=='I') 
       {
         if(i+1<s.length()&&s[i+1]!='I') sum-=1;
         else sum+=1;              
       }  
       if(s[i]=='V') sum+=5;
       if(s[i]=='X') sum+=10;
       if(s[i]=='L') sum+=50;  
       if(s[i]=='C') sum+=100;
       if(s[i]=='D') sum+=500;   
       if(s[i]=='D') sum+=1000;    
     }             
     cout<<sum<<endl;
   }
   //while(1);
   return 0;
 }

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(cin>>s){
		int b[2][100000]={0};bool bb[2][100000]={0};
		int a[s.size()],sum=0;
		for(int i=0;i<s.size();i++){
			int t;
			if(s[i]=='I')t=1;
			if(s[i]=='V')t=5;
			if(s[i]=='X')t=10;
			if(s[i]=='L')t=50;
			if(s[i]=='C')t=100;
			if(s[i]=='D')t=500;
			if(s[i]=='M')t=1000;
			a[i]=t;
			if(i&&a[i]!=a[i-1]&&b[0][a[i]])b[1][t]++;
			else b[0][t]++;
		}
		for(int i=s.size()-1;i>=0;i--){
			if(sum<a[i]){
				if(i!=s.size()-1&&a[i]!=a[i+1]&&bb[0][a[i]]){
					sum-=b[1][a[i]]*a[i];
				    i-=b[1][a[i]]-1;
				}
				else{sum+=b[0][a[i]]*a[i];
				i-=b[0][a[i]]-1;bb[0][a[i]]=1;}
			}		
			else{
				sum-=b[0][a[i]]*a[i];
				    i-=b[0][a[i]]-1;
				    bb[0][a[i]]=1;
			}
		}
		cout<<sum<<endl;
	}
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<(int)n;++i)
typedef vector<int> vi;
 
int main()
{
    map<char, int> roma;
    roma.insert(make_pair('I', 1));
    roma.insert(make_pair('V', 5));
    roma.insert(make_pair('X', 10));
    roma.insert(make_pair('L', 50));
    roma.insert(make_pair('C', 100));
    roma.insert(make_pair('D', 500));
    roma.insert(make_pair('M', 1000));
 
    char str[128];

    while(scanf("%s", str) != EOF){
        int v = 0;
        rep(i, strlen(str)){
            if(i && roma[str[i-1]]<roma[str[i]])
                v -= roma[str[i-1]]*2;
            v += roma[str[i]];
        }
        printf("%d\n", v);
    }
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

typedef long long ll;
using namespace std;

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

int main(){
	string str;
	while(1){
		cin >> str;

		int sum=0;
		stack<int> stk;
		for(int i=0;i<str.size();i++){
			char* pos;
			if((pos = find(name,name+7,str[i])) != name+7){
				int next;
				int now = num[pos-name];

				char* nextpos;
				if(i+1 < str.size()
					&& (nextpos = find(name,name+7,str[i+1])) != name+7){
					next = num[nextpos-name];
				}else{
					next = -1;
				}

				if(now >= next){
					sum += now;
				}else{
					sum += next - now;
					i++;
				}
			}
		}
		cout << sum << endl;

		if(cin.eof()) break;
	}
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int c[256];
    c['I'] = 1;
    c['V'] = 5;
    c['X'] = 10;
    c['L'] = 50;
    c['C'] = 100;
    c['D'] = 500;
    c['M'] = 1000;

    for(;;){
        string s;
        if(!(cin >> s))
            return 0;

        int n = s.size();
        int ret = 0;
        for(int i=0; i<n; ++i){
            if(i+1 < n && c[s[i]] < c[s[i+1]])
                ret -= c[s[i]];
            else
                ret += c[s[i]];
        }
        cout << ret << endl;
    }
}

C++: int main() {
  int a[10], b, c, n;
  bool judge;
 
  cin >> n;
  REP(i, n) {
    REP(j, 10) cin >> a[j];
    b = 0;
    c = 0;
    judge = true;
    REP(j, 10) {
      if(a[j] < b && a[j] < c) {
    judge = false;
    break;
      }
      else if(b < a[j] && c < a[j]) {
    if(b > c) b = a[j];
    else c = a[j];
      }
      else if(b < a[j] && c > a[j]) b = a[j];
      else if(b > a[j] && c < a[j]) c = a[j];
      else {
    if(b > c) b = a[j];
    else c = a[j];
      }
    }
    if(judge) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

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

int main() {
    char input[1000];
    while (cin >> input) {
        char pre = '0';
        int output = 0;
        for (int i = 0; input[i] != '\0'; i++) {
            switch (input[i]) {
            case 'M':
                output += (pre == 'C') ? 800 : 1000;
                break;
            case 'D':
                output += (pre == 'C') ? 300 : 500;
                break;
            case 'C':
                output += (pre == 'X') ? 80 : 100;
                break;
            case 'L':
                output += (pre == 'X') ? 30 : 50;
                break;
            case 'X':
                output += (pre == 'I') ? 8 : 10;
                break;
            case 'V':
                output += (pre == 'I') ? 3 : 5;
                break;
            case 'I':
                output++;
                break;
            }
            pre = input[i];
        }
        cout << output << endl;
    }
}

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

using namespace std;


#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

int main(){
	string S;
	map<char,int> m={{'I',1},{'V',5},{'X',10},{'L',50},{'C',100},{'D',500},{'M',1000}};
	while (cin>>S){
		int ans=0;
		REP(i,S.length()-1){
			if (m[S[i]]>=m[S[i+1]]){
				ans+=m[S[i]];
			}else{
				ans-=m[S[i]];
			}
		}
		ans+=m[S[S.length()-1]];
		cout<<ans<<endl;
	}
	return 0;
}