Cod sursa(job #1288678)

Utilizator AndreiPopescu999Andrei Popescu AndreiPopescu999 Data 8 decembrie 2014 23:16:17
Problema Perle Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <cstring>
#define dvect 10001;
using namespace std;
ifstream fin("perle.in");
ofstream fout("perle.out");
int n,a[10001],i,j,l,k;
int B(int x);
int C(int x);
int B(int x)
{
    if(a[x]==2)
      return B(x+1);
    if(a[x]==1&&a[x+2]==3)
      return C(x+4);
      return 0;
}
int C(int x)
{
    if(a[x]==2)
      return x+1;
    if(a[x]==3)
      return C(B(x+1));
    if(a[x]==1&&a[x+1]==2)
      return x+3;
}
int main()
{
    fin>>n;
    for(i=1;i<=n;i++){
        fin>>l;
        for(j=1;j<=l;j++)
            fin>>a[j];
        if(l==1||B(1)==l+1||C(1)==l+1)
            fout<<1<<"\n";
        else
            fout<<0<<"\n";
    }
    return 0;
}