- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
package mypackage;
import java.io.*;
public class RimToArab {
public static void main(String [] args){
System.out.println("Enter the Roman numeral:");
String Rim = "";
char[] Rch = {'I','V','X','L','C','D','M'};
int[] Acf = {1,5,10,50,100,500,1000};
int i,j=0,rez=0;
try {
BufferedReader d = new BufferedReader(new InputStreamReader(System.in));
Rim = d.readLine();
} catch (IOException e) {
System.out.println("Input error!");
}
for (int c = Rim.length()-1; c>=0; --c ){
for(i=6;i>=0; --i){
if (Rch[i]==Rim.charAt(c)){
if (j>Acf[i]){
rez=rez-Acf[i];
} else {
rez=rez+Acf[i];
}
j=Acf[i];
}
}
}
if (rez!=0){
System.out.println(rez);
} else {
System.out.println("Wrong format of input!");
}
}
}