Pagini recente » Cod sursa (job #1797349) | Cod sursa (job #1310263) | Cod sursa (job #3036870) | Cod sursa (job #1279308) | Cod sursa (job #1878065)
#include <iostream>
#include <fstream>
using namespace std;
int v[10005],t,n,i,j,ok;
int pot(char a,int ch)
{
if(ch==0||ch>n) return 0;
if(a=='A') return ch;
if(a=='B')
{
if(v[ch]==1&&v[ch+2]==3)
return pot('C',ch+4);
if(v[ch]==2)
return (pot('B',ch+1));
}
if(a=='C')
{
if(v[ch]==1&&v[ch+1]==2)
return pot('A',ch+2);
if(v[ch]==2) return ch;
if(v[ch]==3) return pot('C',pot('B',ch+1));
}
return 0;
}
int main()
{
ifstream f("perle.in");
ofstream g("perle.out");
f>>t;
for(int cnt=1;cnt<=t;cnt++)
{
f>>n;
for(i=1;i<=n;i++)
f>>v[i];
ok=0;
ok|=(pot('A',1)==n);
if(!ok) ok|=(pot('B',1)==n);
if(!ok) ok|=(pot('C',1)==n);
for(i=1;i<=n;i++)
v[i]=0;
g<<ok<<'\n';
}
return 0;
}