import java.util.*;

class roman_to_integer{

public static void main(String[] args){

System.out.println("Welcome to Converting Roman to integer Conversion:-"); System.out.println(".................................................");

Scanner sc= new Scanner(System.in);

System.out.println("Enter the Roman Number:-");

String x=sc.nextLine(); x=x.toUpperCase();

System.out.println("Entered Roman Number is : "+x);

int n=x.length();

System.out.println("Number Of Charecters the String Contains : "+n);

int res=0;

for(int i=0;i< n-1;i++){ int x1=val(x.charAt(i));

int x2=val(x.charAt(i+1));

System.out.println("charAt["+i+"] : "+x1+", charAt["+(i+1)+"] : "+x2);

if(x1 < x2){

res = res-x1;

}else{

res=res+x1;

}

}

res=res+val(x.charAt(n-1));

System.out.println("Integer is : "+ res);

}

public static int val(char x){

switch(x){

case 'M':

return 1000;

case 'D':

return 500;

case 'C':

return 100;

case 'L':

return 50;

case 'X':

return 10;

case 'V':

return 5;

case 'I':

return 1;

default:

return 0;

}

}

}