Cod sursa(job #938539)

Utilizator Pop_EmilPal Tamas Pop_Emil Data 12 aprilie 2013 20:45:13
Problema Perle Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>
using namespace std;

int T,n,s[10050];

void _read()
{
  freopen("perle.in","r",stdin);
  freopen("perle.out","w",stdout);

  scanf("%d",&T);
}

int c(int w);

int b(int w)
{
  if(w>n)return -1;
  if(s[w]==2)return b(w+1);
  if(s[w]==1 && s[w+2]==3)return c(w+4);

  return -1;
}

int c(int w)
{
  if(w>n)return -1;
  if(s[w]==2) return w+1;
  if(s[w]==1 && s[w]==2) return w+3;
  if(s[w]==3) return c(b(w+1));

  return -1;
}

int main()
{
_read();
int i;

while(T--)
 {
  scanf("%d",&n);
  for( i=0;i<n;i++)
    scanf("%d",&s[i]);


  if(n==1 || b(0)==n || c(0)==n)printf("1 \n");
                                else printf("0 \n");

 }


return 0;
}