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.
here is my code
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;
}
}
Re: Runtime Error running in UVA