Pagini recente » Cod sursa (job #1945466) | Cod sursa (job #1181105) | Cod sursa (job #2528529) | Cod sursa (job #918809) | Cod sursa (job #1224701)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXL 10015
using namespace std;
int a[MAXL];
int n, len;
void sol();
void citire()
{
scanf("%d ", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &len);
for (int j = 0; j < len; j++)
scanf("%d", &a[j]);
sol();
}
}
int C(int);
int B(int pos)
{
if (pos > len)
return 0;
if (a[pos] == 2)
return B(pos+1);
if (a[pos] == 1 && a[pos+2] == 3)
return C(pos+4);
return 0;
}
int C(int pos)
{
if (pos > len)
return 0;
if (a[pos] == 2)
return pos + 1;
if (a[pos] == 3)
return C(B(pos+1));
if (a[pos] == 1 && a[pos+1] == 2)
return pos + 3;
return 0;
}
void sol()
{
if (len == 1 || B(0) == len || C(0) == len)
printf("1\n");
else
printf("0\n");
}
int main()
{
freopen("perle.in", "r", stdin);
freopen("perle.out", "w", stdout);
citire();
return 0;
}