1. JAVA, Gunnar Hage


/**
* FWP-Fach: ACM programming Contest WS 08/09 "759 - The Return of the Roman Empire"
* Verdict: accepted
*
* Gunnar Hage, gunnarhage@gmx.de
* AP5(IFB5A) Jan. 2009
IN:
MCMXCVIII
CCM
OUT
1998
This is not a valid number

weitere testfälle.
XD
XCIM
XCID
ID
CMXDIV
XDI

MMMM
MMMMM
MMMMDCCCLXIV
IC
IVXCDDLCLVIVID
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
public class Main {

public static void main(String... args) throws IOException{
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int zahl = 0;
boolean d=false, l=false, v = false;
String roman;
while(br.ready())
{
roman = br.readLine();
if(roman.equals(""))
roman = "zero123";
if(roman.startsWith("M"))
{
roman = roman.substring(1,roman.length());
zahl = zahl + 1000;
}

if(roman.startsWith("M"))
{
roman = roman.substring(1,roman.length());
zahl = zahl + 1000;
}

if(roman.startsWith("M"))
{
roman = roman.substring(1,roman.length());
zahl = zahl + 1000;
}

if(roman.startsWith("CM"))
{
roman = roman.substring(2,roman.length());
zahl = zahl + 900;
}
else if (roman.startsWith("D"))
{
roman = roman.substring(1,roman.length());
d = true;
zahl = zahl + 500;
}
else if(roman.startsWith("CD"))
{
roman = roman.substring(2,roman.length());
zahl = zahl + 400;
}
else
d = true;
if(roman.startsWith("CCC") && d)
{
roman = roman.substring(3,roman.length());
zahl = zahl + 300;
}
else if(roman.startsWith("CC") && d)
{
roman = roman.substring(2,roman.length());
zahl = zahl + 200;
}
else if(roman.startsWith("C") && d)
{
roman = roman.substring(1,roman.length());
zahl = zahl + 100;
}

if(roman.startsWith("XC"))
{
roman = roman.substring(2,roman.length());
zahl = zahl + 90;
}
else if (roman.startsWith("L"))
{
roman = roman.substring(1,roman.length());
l = true;
zahl = zahl + 50;
}
else if(roman.startsWith("XL"))
{
roman = roman.substring(2,roman.length());
zahl = zahl + 40;
}
else
l = true;
if(roman.startsWith("XXX") && l)
{
roman = roman.substring(3,roman.length());
zahl = zahl + 30;
}
else if(roman.startsWith("XX") && l)
{
roman = roman.substring(2,roman.length());
zahl = zahl + 20;
}
else if(roman.startsWith("X") && l)
{
roman = roman.substring(1,roman.length());
zahl = zahl + 10;
}

if(roman.startsWith("IX"))
{
roman = roman.substring(2,roman.length());
zahl = zahl + 9;
}
else if (roman.startsWith("V"))
{
roman = roman.substring(1,roman.length());
v = true;
zahl = zahl + 5;
}
else if(roman.startsWith("IV"))
{
roman = roman.substring(2,roman.length());
zahl = zahl + 4;
}
else
v = true;
if(roman.startsWith("III") && v)
{
roman = roman.substring(3,roman.length());
zahl = zahl + 3;
}
else if(roman.startsWith("II") && v)
{
roman = roman.substring(2,roman.length());
zahl = zahl + 2;
}
else if(roman.startsWith("I") && v)
{
roman = roman.substring(1,roman.length());
zahl = zahl + 1;
}
if(roman.length() == 0)
bw.append(zahl + "\n");
else if(roman.equals("zero123"))
bw.append("" + 0);
else
bw.append("This is not a valid number\n");
zahl = 0;
d = l = v = false;
}
bw.flush();
bw.close();
System.exit(0);
}
}