Results 1 to 11 of 11
  1. #1
    mathfxr is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default Runtime Error running in UVA

    Hi all ,im new with java, i write a code which working fine in my machine but when i submit to UVA web it produce runtime error,could anyone help me identify what is the cause of that problem
    .It does not show any specific error for me to look into, it just say that my program didnt finish properly.
    i had change the code too many times but still runtime error.
    here is my code
    Java Code:
    import java.util.*;
    import java.util.Arrays;
    
    
    class BruteForces {
    
        public static int totalsum=0;
        public static String outputAll1="";
        public static String outputAll2="";
    
        public static void main(String[] args) {
    
             
    
            //iniatialize array;
    
    
            Scanner in = new Scanner(System.in);//use system.in to read input
    
    
            int Intdatacase=0;
            String datacase="";
            //get data case
           try { datacase = in.next();
            Intdatacase=Integer.parseInt(datacase);
            } catch ( Exception e) { System.exit(0); }
            if ( datacase == null ) System.exit(0);
    
            int intLoop=0,IntInputsz=0;
            String InputDatas="";
            if(Intdatacase>15||Intdatacase<1)System.exit(0);
            for(intLoop=0;intLoop<Intdatacase;intLoop++){
              outputAll1="";
              outputAll2="";
              String[] InputDatasLoopAr1;
              String[] InputDatasLoopAr2;
              String InputDatasLoopA="",InputDatasLoopA2="";
              //get input for each case
               InputDatas="";
    
    
              
              //get how many words in a cases
                    try { IntInputsz = in.nextInt();
    
                            } catch ( Exception e) { break; }
    
                    //enter first words
                    if(IntInputsz>0&&IntInputsz<=100){
    
                    try{
    
                     InputDatas = in.next();
                                     InputDatas=InputDatas.toLowerCase().trim();
                                     if(InputDatas.length()>100)break;
                       } catch ( Exception e) { break; }
                        if ( InputDatas == null ) break;
                    }
                    else break;
                    for(int i=0;i<IntInputsz-1;i++)
                    {
    
                                String InputDatasLoop="";
                                //get next word if size word >1
                                try { InputDatasLoop = in.next();
                                        InputDatasLoop=InputDatasLoop.toLowerCase().trim();
                                        if(InputDatasLoop.length()>100)break;
                                } catch ( Exception e) {
    
                                    break; }
                                if ( InputDatasLoop == null ) {break;}
    
                        if(InputDatasLoop.charAt(0)==InputDatas.charAt(0))
                                    {
                                        InputDatasLoopA=InputDatasLoopA+InputDatasLoop.toLowerCase()+" ";
                                    }
                        else
                                    InputDatasLoopA2=InputDatasLoopA2+InputDatasLoop.toLowerCase()+" ";
    
                    }
    
                InputDatasLoopAr1=InputDatasLoopA.split(" ");
                InputDatasLoopAr2=InputDatasLoopA2.split(" ");
    
                Arrays.sort(InputDatasLoopAr1);
                    Arrays.sort(InputDatasLoopAr2);
    
                    totalsum=InputDatas.length();//get first value of word
                    outputAll1=InputDatas;//insert first word
                    if(InputDatasLoopA.length()>1)
                    calculate(InputDatasLoopAr1,InputDatas,"A",totalsum);//calculate for first array
                    InputDatas="";//clear inputdatas
                       if(InputDatasLoopA2.length()>1)
                    calculate(InputDatasLoopAr2,InputDatas,"D",totalsum);//calculate for second array
                   
                    System.out.printf(totalsum+"\n"+outputAll1+"\n"+outputAll2);//display output
                    
            //intLoop++;
    
            }
    
    
            System.exit(0);
        }
    
    public static void calculate(String[] strArray,String InputDatas,String Arrange,int total)
    {               int LastIndex=InputDatas.length(),CountNext=0;
                   int InputDatasB=0,Loops=0;
                 
          for(int iz=0;iz<strArray.length;)
            {
    
    
              if((InputDatasB==1&&!strArray[iz].equals("-"))||(InputDatas.equals("")&&!strArray[iz].equals("-")))
              {
                 InputDatas=strArray[iz];
                 LastIndex=strArray[iz].length();
                 InputDatasB=0;
                 totalsum+=LastIndex;
    
              }
              if(!strArray[iz].equals("-")){
    
                int pos2 = strArray[iz].indexOf(InputDatas.substring(0, LastIndex));
                if(pos2==0)
                {
                        if(Arrange.equals("D"))
                        outputAll2=strArray[iz]+"\n"+outputAll2;
                        else
                        outputAll1=outputAll1+"\n"+strArray[iz];
    
                        totalsum+=(strArray[iz].length()-LastIndex);
    
                        InputDatas=strArray[iz];
                        LastIndex=strArray[iz].length();
                        strArray[iz]="-";
                        Arrays.sort(strArray);
                }
              }
                iz++;
                   //    CountNext=iz+1;
                    if(iz==strArray.length)
                    {
    
                     iz=0;
                     LastIndex--;
    
                    }
    
                    if(LastIndex==0)
                    {
                       InputDatasB=1;
    
                    }
                    if(strArray[strArray.length-1].equals("-")){
                      //          Loops=1;
                        break;
                    }
    
            
              }
            return;
    
    }
    
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    Have you run the program in a command prompt window successfully?
    What is the program supposed to do? Can you execute the program and copy and paste here the console from when you run it?

  3. #3
    mathfxr is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    This is based on uva problem number 10602 editor nottoobad.
    Yerp i succesfully enter some test data, but when submit it to uva it said runtime error which i dont have any clue, i try to change the code to many times but the same result.

    Sample Input
    3
    3
    this
    thin
    thing
    4
    popcorn
    apple
    apricote
    plum
    2
    hello
    hello
    output
    6
    this
    thin
    thing
    21
    popcorn
    plum
    apricote
    apple
    5
    hello
    hello

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,526
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by mathfxr View Post
    but when submit it to uva
    Please elaborate; is 'uva' the University of Amsterdam? What happens there? How is your program run there? Is there a stdin Stream?

    kind regards,

    Jos
    Last edited by JosAH; 09-17-2010 at 08:23 PM.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    What happens when YOU execute the program?
    Copy the full console and paste it here. If you are on Windows:
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  6. #6
    mathfxr is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    U can know about uva by visit this url
    uva.onlinejudge.org

    here the content that i enter to the console
    D:\java>javac BruteForces.java

    D:\java>java BruteForces
    3
    3
    this
    thing
    thin
    6
    this
    thin
    thing
    4
    popcorn
    apple
    apricote
    plum
    21
    popcorn
    plum
    apricote
    apple
    2
    hello
    hello
    5
    hello
    hello

    D:\java>

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    If you don't get an error, why would I get an error with the same input as you are using?
    There is nothing to work on with out an error or some info from whoever is telling you your code has a problem. Get them to explain in more detail.

  8. #8
    mathfxr is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    Java Code:
    import java.util.*;
    import java.util.Arrays;
    
    
    class BruteForces {
    
        public static int totalsum=0;
        public static String outputAll1="";
        public static String outputAll2="";
    
        public static void main(String[] args) {
    
             
    
    		//iniatialize array;
    
    
            Scanner in = new Scanner(System.in);//use system.in to read input
    
    
            int Intdatacase=0;
            String datacase="";
            //get the data case
           try { datacase = in.next();
            Intdatacase=Integer.parseInt(datacase);
            } catch ( Exception e) { System.exit(0); }
            if ( datacase == null ) System.exit(0);
    
            int intLoop=0,IntInputsz=0;
            String InputDatas="";
            if(Intdatacase>15||Intdatacase<1)System.exit(0);//check datacase condition
            for(intLoop=0;intLoop<Intdatacase;intLoop++){//loop depend on datacase
              outputAll1="";
              outputAll2="";
              String[] InputDatasLoopAr1;
              String[] InputDatasLoopAr2;
              String InputDatasLoopA="",InputDatasLoopA2="";
              //get input for each case
               InputDatas="";
    
    
              
              //get how many numbers of words line in a cases
                    try { IntInputsz = in.nextInt();
    
                            } catch ( Exception e) { break; }
    
    			    
    			    if(IntInputsz>0&&IntInputsz<=100){//check condition of words enter
    				//get the first words
    			    try{
    
    				 InputDatas = in.next();
                                     InputDatas=InputDatas.toLowerCase().trim();
                                     if(InputDatas.length()>100)break;
                       } catch ( Exception e) { break; }
                        if ( InputDatas == null ) break;
            		}
            		else break;
            		//if the number of words line >1
            		for(int i=0;i<IntInputsz-1;i++)
            		{
    
                                String InputDatasLoop="";
                                //get next word if size word >1
                                try { InputDatasLoop = in.next();
                                        InputDatasLoop=InputDatasLoop.toLowerCase().trim();
                                        if(InputDatasLoop.length()>100)break;
                                } catch ( Exception e) {
    
                                	break; }
                                if ( InputDatasLoop == null ) {break;}
    
            			if(InputDatasLoop.charAt(0)==InputDatas.charAt(0))//check whether input at index 0 equal with InputDatas to group it
                                    {
                                        InputDatasLoopA=InputDatasLoopA+InputDatasLoop.toLowerCase()+" ";//add data into string
                                    }
            			else//if not equal put it in second string
                                    InputDatasLoopA2=InputDatasLoopA2+InputDatasLoop.toLowerCase()+" ";//add data 
    
            		}
    
    			InputDatasLoopAr1=InputDatasLoopA.split(" ");//split the string into first array
    			InputDatasLoopAr2=InputDatasLoopA2.split(" ");//split the string into second array
    
    			
    				Arrays.sort(InputDatasLoopAr2);//sort the second array 
    
                    totalsum=InputDatas.length();//get first value of word let say word hello contain 5 char so totalsum become 5
                    outputAll1=InputDatas;//insert first word for output
                    if(InputDatasLoopA.length()>1)//if 1st array not empty run calculate function to calculate word char in the array
                    {
                    Arrays.sort(InputDatasLoopAr1);//sort the first array 
                    calculate(InputDatasLoopAr1,InputDatas,"A",totalsum);//calculate for first array
                    }
                    InputDatas="";//clear inputdatas
                   	if(InputDatasLoopA2.length()>1)//if 2nd array not empty run calculate function to calculate word char in the array
                   	{	Arrays.sort(InputDatasLoopAr2);//sort the second array 
                   		calculate(InputDatasLoopAr2,InputDatas,"D",totalsum);//calculate for second array
                   	}
                    System.out.printf(totalsum+"\n"+outputAll1+"\n"+outputAll2);//display output
    				
            //intLoop++;
    
            }
    
    
            System.exit(0);
        }
    
    public static void calculate(String[] strArray,String InputDatas,String Arrange,int total)
    {               int LastIndex=InputDatas.length(),CountNext=0;
                   int InputDatasB=0,Loops=0;
                 
          for(int iz=0;iz<strArray.length;)
            {
    
    			//if the last index of char =0 or inputdatas is empty retrieve new value
              if((InputDatasB==1&&!strArray[iz].equals("-"))||(InputDatas.equals("")&&!strArray[iz].equals("-")))
              {
                 InputDatas=strArray[iz];//get new data for InputDatas
                 LastIndex=strArray[iz].length();//Get Last index
                 InputDatasB=0;//reset InputDatasB to 0
                 totalsum+=LastIndex;//sum the the new number character
    
              }
              
              if(!strArray[iz].equals("-")){//run if string not equal "-"
    
                int pos2 = strArray[iz].indexOf(InputDatas.substring(0, LastIndex));//compare strArray with inputdatas
                if(pos2==0)//check whether strArray[iz] contain InputDatas substring from 0 to LastIndex
                {
                	//arrangement of output
                        if(Arrange.equals("D"))
                        outputAll2=strArray[iz]+"\n"+outputAll2;
                        else
                        outputAll1=outputAll1+"\n"+strArray[iz];
    
                        totalsum+=(strArray[iz].length()-LastIndex);//calculate the number of char which not equal with InputDatas ex. 
    
                        InputDatas=strArray[iz];//replace InputDatas with new value
                        LastIndex=strArray[iz].length();//get the Last Index number for new data
                        strArray[iz]="-";//set the array to - after calculate
                        Arrays.sort(strArray);//sort back the array since it contain "-"
                }
              }
    			iz++;
               	//	CountNext=iz+1;
                    if(iz==strArray.length)//if still have word in the array but loop is reach limit reset the loop
                    {
    
                     iz=0;//reset loop 
                     LastIndex--;//reduce the index to find similar characters
    
                    }
    
                    if(LastIndex==0)//check if the Lastindex=0 this mean that there are no matching character
                    {
                       InputDatasB=1;//Set InputDatasB to 1 to retrieve new inputdatas in next loop
    
                    }
                    if(strArray[strArray.length-1].equals("-")){
              		//          Loops=1;
                        break;//break loop if the last index equal "-";
    				}
    
            
              }
            return;
    
    }
    
    }
    What kind of error do you get?it is weird if u got errors and im not.could you let me know what is the errors did u get? Did you use any special option for compiling or running?

    Thanks for helping me out.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    I didn't get any errors.
    I changed your program by hardcoding the responses to the Scanner vs running the program in a command prompt window.
    Can you change the program to be completely selfcontained, ie NOT to require any user input and see what happens with the program that way.

    For example add this class with the correct input supplied to your test program:
    Java Code:
        // Inline replacement class for Scanner
        static class GetInput {
          int intIdx = 0;   // index to theStrings
          int strIdx = 0;   // index to theInts
          // The data to be returned:
          final String[] theStrings = {"3", "this", "thing", "thin"};
          final int[] theInts = {3, 4};
         // Methods to return the data
         String next() {
            System.out.println(theStrings[strIdx]); // show what was read
            return theStrings[strIdx++];
         }
         int nextInt() {
            System.out.println(theInts[intIdx]); // show what was read
            return theInts[intIdx++];
         }
       } // end class GetInput
    Modify your code by commenting out the Scanner usage and adding a new statement:
    Java Code:
    //        Scanner in = new Scanner(System.in);//use system.in to read input
            GetInput in = new GetInput();
    Last edited by Norm; 09-18-2010 at 01:52 AM.

  10. #10
    mathfxr is offline Member
    Join Date
    Sep 2010
    Posts
    8
    Rep Power
    0

    Default

    Do you want me to used the class that u provided or alter it by my self?
    i alter it based on my understanding

    this is the coding
    Java Code:
    import java.util.*;
    import java.util.Arrays;
    
    
    class BruteForces {
    
        public static int totalsum=0;
        public static String outputAll1="";
        public static String outputAll2="";
    
        public static void main(String[] args) {
    
             
    
    		//iniatialize array;
    
    
            Scanner in = new Scanner(System.in);//use system.in to read input
    
    
            int Intdatacase=1;
            String datacase="";
            //get the data case
    //       try { datacase = in.next();
    //        Intdatacase=Integer.parseInt(datacase);
    //        } catch ( Exception e) { System.exit(0); }
    //        if ( datacase == null ) System.exit(0);
    
            int intLoop,IntInputsz=0;
            
            if(Intdatacase>15||Intdatacase<1)System.exit(0);//check datacase condition
            for(intLoop=0;intLoop<Intdatacase;intLoop++){//loop depend on datacase
              outputAll1="";
              outputAll2="";
              String[] InputDatasLoopAr1;
              String[] InputDatasLoopAr2;
              String InputDatasLoopA="",InputDatasLoopA2="";
              String[] InputDatas={"this","thin","thing","gayus"};
              //get input for each case
    //           InputDatas="";
    				IntInputsz=4;//new
    			
    			
    
              
              //get how many numbers of words line in a cases
    //                try { IntInputsz = in.nextInt();
    //
    //                        } catch ( Exception e) { break; }
    //
    //			    
    //			    if(IntInputsz>0&&IntInputsz<=100){//check condition of words enter
    //				//get the first words
    //			    try{
    //
    //				 InputDatas = in.next();
    //                                 InputDatas=InputDatas.toLowerCase().trim();
    //                                 if(InputDatas.length()>100)break;
    //                   } catch ( Exception e) { break; }
    //                    if ( InputDatas == null ) break;
    //        		}
    //        		else break;
            		//if the number of words line >1
            		for(int i=1;i<IntInputsz;i++)
            		{
    
                                String InputDatasLoop=InputDatas[i];
                                //get next word if size word >1
    //                            try { InputDatasLoop = in.next();
    //                                    InputDatasLoop=InputDatasLoop.toLowerCase().trim();
    //                                    if(InputDatasLoop.length()>100)break;
    //                            } catch ( Exception e) {
    //
    //                            	break; }
    //                            if ( InputDatasLoop == null ) {break;}
    
            			if(InputDatasLoop.charAt(0)==InputDatas[0].charAt(0))//check whether input at index 0 equal with InputDatas to group it
                                    {
                                        InputDatasLoopA=InputDatasLoopA+InputDatasLoop.toLowerCase()+" ";//add data into string
                                    }
            			else//if not equal put it in second string
                                    InputDatasLoopA2=InputDatasLoopA2+InputDatasLoop.toLowerCase()+" ";//add data 
    
            		}
    
    			InputDatasLoopAr1=InputDatasLoopA.split(" ");//split the string into first array
    			InputDatasLoopAr2=InputDatasLoopA2.split(" ");//split the string into second array
    
    			
    				 
    
                    totalsum=InputDatas[0].length();//get first value of word let say word hello contain 5 char so totalsum become 5
                    outputAll1=InputDatas[0];//insert first word for output
                    if(InputDatasLoopA.length()>1)//if 1st array not empty run calculate function to calculate word char in the array
                    {
                    Arrays.sort(InputDatasLoopAr1);//sort the first array 
                    calculate(InputDatasLoopAr1,InputDatas[0],"A",totalsum);//calculate for first array
                    }
                    InputDatas[0]="";//clear inputdatas
                   	if(InputDatasLoopA2.length()>1)//if 2nd array not empty run calculate function to calculate word char in the array
                   	{	Arrays.sort(InputDatasLoopAr2);//sort the second array 
                   		calculate(InputDatasLoopAr2,InputDatas[0],"D",totalsum);//calculate for second array
                   	}
                    System.out.printf(totalsum+"\n"+outputAll1+"\n"+outputAll2);//display output
    				
            //intLoop++;
    
            }
    
    
            System.exit(0);
        }
    
    public static void calculate(String[] strArray,String InputDatas,String Arrange,int total)
    {               int LastIndex=InputDatas.length(),CountNext=0;
                   int InputDatasB=0,Loops=0;
                 
          for(int iz=0;iz<strArray.length;)
            {
    
    			//if the last index of char =0 or inputdatas is empty retrieve new value
              if((InputDatasB==1&&!strArray[iz].equals("-"))||(InputDatas.equals("")&&!strArray[iz].equals("-")))
              {
                 InputDatas=strArray[iz];//get new data for InputDatas
                 LastIndex=strArray[iz].length();//Get Last index
                 InputDatasB=0;//reset InputDatasB to 0
                 totalsum+=LastIndex;//sum the the new number character
    
              }
              
              if(!strArray[iz].equals("-")){//run if string not equal "-"
    
                int pos2 = strArray[iz].indexOf(InputDatas.substring(0, LastIndex));//compare strArray with inputdatas
                if(pos2==0)//check whether strArray[iz] contain InputDatas substring from 0 to LastIndex
                {
                	//arrangement of output
                        if(Arrange.equals("D"))
                        outputAll2=strArray[iz]+"\n"+outputAll2;
                        else
                        outputAll1=outputAll1+"\n"+strArray[iz];
    
                        totalsum+=(strArray[iz].length()-LastIndex);//calculate the number of char which not equal with InputDatas ex. 
    
                        InputDatas=strArray[iz];//replace InputDatas with new value
                        LastIndex=strArray[iz].length();//get the Last Index number for new data
                        strArray[iz]="-";//set the array to - after calculate
                        Arrays.sort(strArray);//sort back the array since it contain "-"
                }
              }
    			iz++;
               	//	CountNext=iz+1;
                    if(iz==strArray.length)//if still have word in the array but loop is reach limit reset the loop
                    {
    
                     iz=0;//reset loop 
                     LastIndex--;//reduce the index to find similar characters
    
                    }
    
                    if(LastIndex==0)//check if the Lastindex=0 this mean that there are no matching character
                    {
                       InputDatasB=1;//Set InputDatasB to 1 to retrieve new inputdatas in next loop
    
                    }
                    if(strArray[strArray.length-1].equals("-")){
              		//          Loops=1;
                        break;//break loop if the last index equal "-";
    				}
    
            
              }
            return;
    
    }
    
    }

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    I had no errors when I ran your previous code. However, I didn't enter the data you did.
    Does the code you just posted work better than the previous code?
    What is it you are trying to do here with this new version?

Similar Threads

  1. problem with Runtime.getRuntime().exec when running java in .bat
    By Shayko in forum Threads and Synchronization
    Replies: 2
    Last Post: 01-27-2010, 07:46 PM
  2. Replies: 0
    Last Post: 07-13-2009, 05:22 PM
  3. java runtime isn't running
    By v1nsai in forum New To Java
    Replies: 3
    Last Post: 03-31-2009, 07:33 PM
  4. Replies: 3
    Last Post: 01-23-2009, 08:53 AM
  5. Compiling and running code in runtime
    By tim in forum New To Java
    Replies: 4
    Last Post: 01-27-2008, 06:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •