Pagini recente » Cod sursa (job #1264255) | Cod sursa (job #1249986) | Cod sursa (job #106448) | Cod sursa (job #2500285) | Cod sursa (job #2422724)
#include <bits/stdc++.h>
using namespace std;
ifstream f("perle.in");
ofstream g("perle.out");
const int NMAX = 10105;
int n,m;
int v[NMAX];
int c(int poz);
int a(int poz){
return poz + 1;
}
int b(int poz){
if(v[poz] == 2) return b(poz + 1);
if(v[poz] == 1 || v[poz + 2] == 3) return c(poz + 4);
return 0;
}
int c(int poz){
if(v[poz] == 2) return poz + 1;
if(v[poz] == 3) return c(b(poz + 1));
if(v[poz] == 1 && v[poz + 1] == 2) return a(poz + 2);
return 0;
}
int main(){
int i;
f >> m;
while(m){
f >> n;
for(i = 1 ; i <= n ; i++)
f >> v[i];
if(a(1) == n + 1 || b(1) == n + 1 || c(1) == n + 1)
g << 1 << "\n";
else
g << 0 << "\n";
m--;
}
return 0;
}