Pagini recente » Cod sursa (job #2769017) | Cod sursa (job #916600) | Cod sursa (job #2946270) | Cod sursa (job #1412723) | Cod sursa (job #553110)
Cod sursa(job #553110)
Program perle;
TYPE trei=1..3;
TYPE vector=array[1..10000] of trei;
TYPE vectors=array[1..100] of char;
var L,n:integer;
v:vector;
s:vectors;
f:text;
procedure perla;
var i,u:integer;
ok:boolean;
begin
u:=1;ok:=true;i:=1;
if l=1 then ok:=false
else if (v[1]=1) and (v[3]=3) then begin s[1]:='C';i:=5; end
else if v[1]=2 then begin s[1]:='B';i:=2; end
else if v[1]=3 then begin s[1]:='C';s[2]:='B';u:=2;i:=2; end
else if (v[1]=1) and (v[2]=2) and (l=3) then ok:=false;
repeat
if (s[u]='B') and (v[i]=1) and (v[i+2]=3) then begin s[u]:='C';i:=i+4; end
else if (s[u]='B') and (v[i]=2) then begin s[u]:='B';inc(i); end
else if (s[u]='B') and (v[i]=3) then ok:=false
else if (s[u]='C') and (v[i]=1) and (v[i+1]=2) then begin dec(u);i:=i+3; end
else if (s[u]='C') and (v[i]=2) then begin dec(u);inc(i); end
else if (s[u]='C') and (v[i]=3) then begin inc(i);s[u]:='C';inc(u);s[u]:='B'; end;
until (u=0) or (i=L+1) or (not ok) or (i=L);
if ((u=0) and (i=L+1)) or (l=1) or ((v[1]=1) and (v[2]=2) and (l=3)) then writeln(1)
else writeln(0);
end;
procedure citire;
var i,j:integer;
f:text;
begin
ASSIGN(f,'perle.txt');reset(f);
readln(f,n);
for j:=1 to n do begin
read(f,L);
for i:=1 to l do read(f,v[i]);
readln(f);
perla;
end;
end;
begin
ASSIGN(f,'perle.out');rewrite(f);
citire;
close(f);
end.