Runtime Error

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
mathfxr
New poster
Posts: 3
Joined: Fri Sep 17, 2010 11:44 am

Runtime Error

Post by mathfxr » Fri Sep 17, 2010 4:19 pm

Hi there , this is my first time using UVA, and when i submit my code which working just fine using my machine it produce runtime error which doesnt have any code , when i received an email it say about my program didn't finish properly. and ask me to terminate your code with the exit code 0.
so i revised it too many times.could someone let me know what is the problem?
this is my code

Code: Select all

import java.util.*;
import java.text.Collator;

class BruteForces {

    public static int totalsum=0;
    public static String outputAll1="";
    public static String outputAll2="";

    public static void main(String[] args) {

            String[] InputDatasLoopAr1=new String[100];
            String[] InputDatasLoopAr2=new String[100];
        //iniatialize array;
            for(int i = 0; i <100; i++) {
                InputDatasLoopAr1[i] = new String();
                 InputDatasLoopAr2[i] = new String();
            
            }

        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="";
        while(intLoop<Intdatacase){
          outputAll1="";
          outputAll2="";
          //get input for each case
           InputDatas="";

             
          String InputDatas2 ="";
          //get how many words in a cases
                try { IntInputsz = in.nextInt();
                
                        } catch ( Exception e) { break; }
                
                //enter first words
                try{
                
                 InputDatas = in.next();

                   } catch ( Exception e) { break; }
                    if ( InputDatas == null ) break;

                for(int i=0;i<IntInputsz-1;i++)
                {
        
                            String InputDatasLoop="";
                            //get next word if size word >1
                            try { InputDatasLoop = in.next();  } catch ( Exception e) { 
                                
                                break; }
                            if ( InputDatasLoop == null ) {break;}

                    if(InputDatasLoop.charAt(0)==InputDatas.charAt(0))
                                {
                                    InputDatasLoopAr1[i]=InputDatasLoop;
                                }
                    else
                                InputDatasLoopAr2[i]=InputDatasLoop;
                  
                }

            
    

                sortArray(InputDatasLoopAr1);//sort first array
                sortArray(InputDatasLoopAr2);//sort second array
                totalsum=InputDatas.length();//get first value of word
                outputAll1=InputDatas;//insert first word
                calculate(InputDatasLoopAr1,InputDatas,"A",totalsum);//calculate for first array
                InputDatas="";//clear inputdatas
                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(),counts=1;
                Boolean InputDatasB=false;

      for(int iz=0;iz<100;iz++)
        {

          if(strArray[99].isEmpty())
          {
              break;

              }

          if((InputDatasB==true&&!strArray[iz].isEmpty())||(InputDatas.equals("")&&!strArray[iz].isEmpty()))
          {
             InputDatas=strArray[iz];
             LastIndex=strArray[iz].length();
             InputDatasB=false;
             totalsum+=LastIndex;

          }
            int pos2 = strArray[iz].indexOf(InputDatas.substring(0, LastIndex));
            if(pos2==0&&!strArray[iz].isEmpty())
            {
                    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]="";
            }
            int CountNext=iz+1;
            if(CountNext==strArray.length)
            {
                if(counts==1)
                {

                 iz=0;
                 LastIndex--;
                 sortArray(strArray);
                }

                if(LastIndex==0)
                {  sortArray(strArray);
                   InputDatasB=true;
                   return;
                }
            }
        }
        return;

}
    public static void sortArray(String[] strArray){
                String tmp;
         Collator collator = Collator.getInstance(Locale.UK);

                if (strArray.length == 1) return;
                for (int i = 0; i < strArray.length;i++) {
                    for (int j = i + 1; j < strArray.length; j++) {
                        if( collator.compare(strArray[i], strArray[j] ) > 0 ) {
                        tmp = strArray[i];
                        strArray[i] = strArray[j];
                        strArray[j] = tmp;
                        }
                    }
                }
                return;
    }

}

raisdead
New poster
Posts: 6
Joined: Thu Dec 30, 2010 7:25 pm

Re: Runtime Error

Post by raisdead » Sun Jan 02, 2011 12:46 am

you may want to try and put a try catch around all of the main method to check if it is actually an exception that is terminating the application early. That is what I did to fix the same problem, however I have yet to figure out why...

Stefan_Bialucha
New poster
Posts: 5
Joined: Mon Mar 31, 2008 12:49 am

Re: Runtime Error

Post by Stefan_Bialucha » Sun Mar 27, 2011 1:10 am

Call your class Main, and do not solve the problem in main method directly. Please follow this description: http://acm.uva.es/board/viewtopic.php?f=31&t=7429

Post Reply

Return to “Java”