Pagini recente » Cod sursa (job #2142823) | Cod sursa (job #687446) | Cod sursa (job #2390753) | Cod sursa (job #614002) | Cod sursa (job #1253522)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("perle.in");
ofstream g("perle.out");
int a[10001],i,k,nr,j;
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()
{
f>>nr;
for(j=1;j<=nr;j++)
{
f>>k;
for(i=1;i<=k;i++)
f>>a[i];
if(k==1||B(1)==k+1||C(1)==k+1)
g<<1<<"\n";
else
g<<0<<"\n";
}
return 0;
}