Pagini recente » Cod sursa (job #1813597) | Cod sursa (job #2831975) | Cod sursa (job #515496) | Cod sursa (job #2928160)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("perle.in");
ofstream fout("perle.out");
int v[10001];
int i, n, m;
int B(int poz);
int C(int poz);
int main(){
fin>>n;
while(n--){
fin>>m;
for(i=1;i<=m;i++)
fin>>v[i];
if(m==1||B(1)==m+1||C(1)==m+1)
fout<<1<<"\n";
else
fout<<0<<"\n";
}
}
int B(int poz){
if(v[poz]==2)
return B(poz+1);
else 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;
else if(v[poz]==3)
return C(B(poz+1));
else if(v[poz]==1 && v[poz+1]==2)
return poz+3;
return 0;
}