June cook off 2013 Attic Crossing Problem

here is my code …!

import java.io.*;

class Attic
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int t,arr,days,max;
int[] a=new int[101];
int holes;
t=Integer.parseInt(br.readLine());
for(int k=0;k<t;k++)
{   max=0;
    arr=0;
    days=0;
    holes=0;
String s=br.readLine();
for(int i=0;i<s.length();i++)
{
    holes=0;
    while(s.charAt(i)=='.')
    {
        i++;
        holes++;
    }
     a[arr]=holes;
    arr++;
}

for(int j=0;j<a.length-1;j++)
{
    max=a[j];
     if(a[j+1]>max)
     {
     max=a[j+1];
    }
    if(a[j]<max)
    {
    days++;
    }
}
System.out.println(days);
}

}
}

i want to know y is it showing me wrong answer ?
Coz i have checked it like around 50 times with different inputs i get the correct answers !

pls post your question in the editorial…closing this ques!!

did you try
“.”

Try this case ##.#…#…#…# , the answer must be 2 but your solution gives 3

refer here

you logic is wrong for calculating maximum, try this,

for(int j=0;j<a.length;j++)

{

if(a[j]>max)

{

  max=a[j];

  days++;

}

}

refer http://ideone.com/wag2gH

well your code doesnt work for this inputs …

check sample input #4

3rd case gives output 2 . :frowning:

well i guess my idea of using array is a bit stupid

thanks anyways !

well… you will be surprised to see this… but reopen the solution you will fell laughing… ideone compiler trolled :stuck_out_tongue:

Thats not a valid input “The first and the last characters of P will be #.”

1 Like