Pagini recente » Cod sursa (job #1083414) | Cod sursa (job #90431) | Cod sursa (job #305965) | Cod sursa (job #971554) | Cod sursa (job #641377)
Cod sursa(job #641377)
#include <stdio.h>
#define NMAX 10000
int A[NMAX + 10];
int n;
int B(int); int C(int);
int B(int pos)
{
if (pos > n + 1)
return pos;
if (A[pos] == 2)
return B(pos + 1);
else if (A[pos] == 1 && A[pos + 2] == 3)
return C(pos + 4);
return -1;
}
int C(int pos)
{
if (A[pos] == 2)
return pos + 1;
if (A[pos] == 1 && A[pos + 1] == 2)
return pos + 3;
if (A[pos] == 3)
return C(B(pos + 1));
return -1;
}
int main()
{
freopen("perle.in", "r", stdin);
freopen("perle.out", "w", stdout);
int i, t;
scanf("%d", &t);
for ( ; t; --t) {
scanf("%d", &n);
for (i = 1; i <= n; ++i)
scanf("%d", &A[i]);
if (n == 1) {
printf("1\n");
continue;
}
int res = B(1);
if (res != n + 1)
res = C(1);
if (res == n + 1)
printf("1\n");
else
printf("0\n");
}
return 0;
}