Pagini recente » Cod sursa (job #441052) | Cod sursa (job #1372504) | Cod sursa (job #439938) | Cod sursa (job #1390043) | Cod sursa (job #2272384)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005;
int n;
int v[MAXN];
int A(int poz);
int B(int poz);
int C(int poz);
int C(int poz) {
if (poz > n)
return -1;
if (v[poz] == 2)
return poz;
if (v[poz] == 3)
return C(B(poz + 1));
if (v[poz] == 1 && v[poz + 1] == 2)
return A(poz + 2);
return -1;
}
int B(int poz) {
if (poz > n)
return -1;
if (v[poz] == 2)
return B(poz + 1);
if (v[poz] == 1 && v[poz + 2] == 3)
return C(poz + 4);
return -1;
}
int A(int poz) {
if (poz == n)
return n;
return 0;
}
int main() {
freopen("perle.in", "r", stdin);
freopen("perle.out", "w", stdout);
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &v[i]);
printf("%d\n", (A(1) == n) | (B(1) == n) | (C(1) == n));
}
return 0;
}