S001-AC.cc 1011 Bytes
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int toDecimal(string str)
{
	int n = 0;
	int i = 0;
	char n1, n5, n10;
	while(str[i] == 'M')
	{
		n += 1000;
		i++;
	}
	if(str[i] == 'C' && str[i+1] == 'M')
	{
		n += 900;
		i += 2;
	}
	if(str[i] == 'D')
	{
		n += 500;
		i++;
	}
	if(str[i] == 'C' && str[i+1] == 'D')
	{
		n += 400;
		i += 2;
	}
	while(str[i] == 'C')
	{
		n += 100;
		i++;
	}
	if(str[i] == 'X' && str[i+1] == 'C')
	{
		n += 90;
		i += 2;
	}
	if(str[i] == 'L')
	{
		n += 50;
		i++;
	}
	if(str[i] == 'X' && str[i+1] == 'L')
	{
		n += 40;
		i += 2;
	}
	while(str[i] == 'X')
	{
		n += 10;
		i++;
	}
	if(str[i] == 'I' && str[i+1] == 'X')
	{
		n += 9;
		i += 2;
	}
	if(str[i] == 'V')
	{
		n += 5;
		i++;
	}
	if(str[i] == 'I' && str[i+1] == 'V')
	{
		n += 4;
		i += 2;
	}
	while(str[i] == 'I')
	{
		n += 1;
		i++;
	}
	return n;
}

int main()
{
	string str;
	while(cin >> str)
	{
		str.erase(str.size()-1,1);
		cout << str << " = " << toDecimal(str) << endl;
	}
	return 0;
}