Hello Everyone,
I am facing run time errors in the trouble sort program. I don't know why. I
have tried to cover all the aspects asked. Kindly help me. My code is written
in Java.
The link for the problem is:
https://codingcompetitions.withgoogle.com/codejam/round/00000000000000cb/00000000000079cb
My Code is:
import java.io.*;
class TroubleSortSolution
{
public static void main(String args[])throws IOException
{
InputStreamReader read =new InputStreamReader(System.in);
BufferedReader in =new BufferedReader(read);
int a,b,n,i,j,t=0,c=0,pos=0;
a=Integer.parseInt(in.readLine());
int sol[] =new int[a];
for(b=1;b<=a;b++)
{
n=Integer.parseInt(in.readLine());
int ar[] =new int[n];
for(i=0;i<n;i++)
{
ar[i]=Integer.parseInt(in.readLine());
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-2;j++)
{
if(ar[j]>ar[j+2])
{
t=ar[j];
ar[j]=ar[j+2];
ar[j+2]=t;
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(ar[j]>ar[j+1])
{
pos=j;
c++;
}
}
}
if(c==0)
{
sol[b-1]=0;
}
else
{
sol[b-1]=pos;
}
}
for(b=0;b<a;b++)
{
if(sol[b]==0)
{
System.out.println("Case #:"+(b+1)+" OK");
}
else
{
System.out.println("Case #:"+(b+1)+" "+sol[b]);
}
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/e1219bde-c8ee-40e0-b9f5-d0dcfdf92833%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.