Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

please solve NZEC error in java(little more homework)

$
0
0
import java.io.*;
class parity
{    
    public static void main(String[] args)
    {
       BufferedReader k=new BufferedReader(new InputStreamReader(System.in));
       int i=0,j=0,t,w,n,p=1;
       String match="";
       String subseq="";
       String matches[]=new String[10];
       String seq="01101001";
       try{
       for(t=1;t<499;++t)
       {
          if(seq.charAt(p)=='0')seq=seq+"01101001";
          else seq=seq+"10010110";
          ++p;
       }

       n=Integer.parseInt(k.readLine());

       for(t=0;t<n;++t)
       {
       matches[t]="";

       w=Integer.parseInt(k.readLine());

       w=(2*w)-1;
       j=0;
       subseq="";
       match=k.readLine();
       for(i=0;i<w;i+=2)
       {
          subseq=subseq+match.charAt(i);
          while(true)
          {       if((seq.substring(j,j+(i/2)+1)).equals(subseq)==true)break;
          if(j<(4*((i/2)+1)))++j;
          else {j=-1;break;}
          }
          matches[t]=matches[t]+j+" ";
       }
       }
       for(t=0;t<n;++t)
       {
          System.out.println(matches[t]);
       } } catch(IOException e){return;}
    }
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>