Cod sursa(job #1227698)

Utilizator stoicatheodorStt sas stoicatheodor Data 11 septembrie 2014 13:31:48
Problema Perle Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<fstream>
using namespace std;
ifstream in("perle.in");
ofstream out("perle.out");
int a[10001],i,k,nr,j;
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()
{
    in>>nr;
    for(j=1;j<=nr;j++)
    {
        in>>k;
        for(i=1;i<=k;i++)
        in>>a[i];
        if(k==1||B(1)==k+1||C(1)==k+1)
        out<<1<<endl;
        else
        out<<0<<endl;
	return 0;
}