Pagini recente » Cod sursa (job #2794307) | Cod sursa (job #1172988) | Cod sursa (job #717329) | Cod sursa (job #264752) | Cod sursa (job #362359)
Cod sursa(job #362359)
var v:array[1..10000] of byte;
n,i,j,l:longint;
f,g:text;
function c(poz:word):word;
forward;
function b(poz:word):word;
begin
if l-poz+1<5 then
b:=0
else
if v[poz]=2 then
b:=b(poz+1)
else
if (v[poz]=1) and (v[poz+2]=3) then
b:=c(poz+4);
end;
function c(poz:word):word;
var loc:word;
begin
if v[poz]=2 then
c:=poz+1
else
if (v[poz]=3) and (l-poz>=6) then
begin
loc:=b(poz+1);
if loc=0 then
c:=0
else
c:=c(loc);
end
else
if (l-poz>=2) and (v[poz]=1) and (v[poz+1]=2) then
c:=poz+3
else
c:=0;
end;
begin
assign(f,'perle.in');
assign(g,'perle.out');
reset(f);rewrite(g);
readln(f,n);
for i:=1 to n do
begin
read(f,l);
for j:=1 to l do
read(f,v[j]);
if (l=1) or (b(1)=l+1) or (c(1)=l+1) then
writeln(g,1)
else
writeln(g,0);
end;
close(f);close(g);
end.