import java.util.*;
public class Solution 
{
    public static void main (String []args)
    {
        System.out.println(decimalToRoman(987));
    }
    
    //NUMERALS numeral = NUMERAL.1000.value();

    
    public static String decimalToRoman(int num) 
    
    {
        boolean executeOnce=false;
        boolean hasIncorrectNumeral=true;
        String conversion="";
        int currentNumeral=0;
        int match=0;
        char fourInRowNumeral=' ';
        char incorrectPredecessor=' ';
        String successor="";

        String [] nextHighest = new String[6];
        nextHighest[0] = "I=>V";
        nextHighest[1] = "V=>X";
        nextHighest[2] = "X=>L";
        nextHighest[3] = "L=>C";
        nextHighest[4] = "C=>D";
        nextHighest[5] = "D=>M";
        
        String [] numerals = new String[]{"I","V","X","L","C","D","M"};


        //M=1000, C=100, D=500, L=50, X=10,  V=5,  I=1


        //these have to be descending order

        //return "test";

        //I will first attempt this from recursive perspective..
        //using a class level variable

        //This should much easier than conversion numeral => decimal number

        //we only need to worry about the valid subtractive notations (as a pair)
        
        //do not need to worry about adjacent subtractive notation being in the same range

        //not relevant
        //i.e  IX XC
             //range (1-10)  (range 10-100)

        // these are the valid combinations....

        //String IV =  "IV";
        //String IX =  "IX";
        //String XL =  "XL";
        //String XC =  "XC";
        //String CD=   "CD"; 
        //String CM=   "CM";

        //Also need to consider this rule
        //The xcletters V, L, and D are not repeated.


        //I will work this example using the following two numbers
        //27  and also 19
        //both will bring their own challenges

       
            //main structure of code
            if (num==0)
            {
                return conversion;
            }
                  
            else
            {
                            
            //M=1000, C=100, D=500, L=50, X=10,  V=5,  I=1

            //only way to tackle this challenge is using an if else
            //and check if larger than numbers
            //1000, 500, 100, 50, 10, 5 , 1
            //Map will not work!!!
            //Switch will not work!!!
            //So similar to numeral => decimal, there will be no collections!!!!!

            //do
            //{

                  do
                {

                if (num >= 1000) 
                {
                    currentNumeral++;
                    conversion = conversion + "M";
                    num=num-1000;
                    System.out.println("num is greater than: " + 1000);
                } 
                
                else if (num>=500) 
                {
                    currentNumeral++;
                    conversion = conversion + "D";
                    num=num-500;
                    System.out.println("num is greater than: " + 500);
                }

                else if (num>=100) 
                {
                    currentNumeral++;
                    conversion = conversion + "C";
                    num=num-100;
                    System.out.println("num is greater than: " + 100);
                }

                 else if (num>=50) 
                {
                    
                    currentNumeral++;
                    conversion = conversion + "L";
                    num = num - 50;
                    System.out.println("num is greater than: " + 50);
                }

                 else if (num>=10) 
                {
                    
                    currentNumeral++;
                    conversion = conversion + "X";
                    num = num -10;
                    System.out.println("num is greater than: " + 10);
                }

                 else if (num>=5) 
                {
                   
                    currentNumeral++;
                    conversion = conversion + "V";
                    num = num - 5;
                    System.out.println("num is greater than: " + 5);
                }

                else if (num>=1)
                {
                    currentNumeral++;
                    conversion = conversion + "I";
                    num = num - 1;
                    System.out.println("num is greater than: " + 1);
                }
                else
                {
                    
                }
         

        }  while (num>0);
        
        
        /*
        if nothing before IIII  =>                                    (IV)
        if  V before IIII  => I followed by next highest letter to V  (IX)
        if X before IIII => X followed by IV                          (XIV)
        if L before IIII => L followed by IV                          (LIV)
        if D before IIII => D followed by IV                          (DIV)
        
        if nothing before CCCC => CD                                   (CD)
        if   d before CCCC  => CM                                      (CM)
        if m before CCCC =>  MCD                                       (MCD)
        
        if nothing before XXXX => XL                                    (XL)
        if L before XXXX  => XC                                         (XC)
        if C before XXXX => CXL                                         (CXL)
        if D before XXXX => DXL                                         (DXL)
        if M before XXXX => MXL                                         (MXL)
        */    
        
        }  //end of else    

        return conversion;  

}
}