On Tuesday, April 2, 2019 at 9:31:52 PM UTC+5:30, Andy wrote:
> aren't all these numbers on the same line?
> 
> 
> On Tue, Apr 2, 2019 at 11:15 PM <[email protected]> wrote:
> 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:
> 
> 
>         for(i=0;i<n;i++)
> 
>         {
> 
>             ar[i]=Integer.parseInt(in.readLine());
> 
>         }
>  

According to your advice, I changed the program code. But now its showing wrong 
answer.
My new code is:

import java.io.*;
class Solution
{
    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];
        String s =in.readLine();
        String[] strs = s.trim().split("\\s+");
        for(i=0;i<strs.length;i++)
        {
            ar[i]=Integer.parseInt(strs[i]);
        }
        for(i=0;i<n-2;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-1;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/f8c7de5f-d674-49d5-88da-3466be2f528e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to