uses graph,crt; label 1,2,3; var t,d,m,tx,ty,s,r,z,z1, x,y,xt,yt,xo,yo: integer; prots:real; begin s:=2; x:=1; y:=1; xt:=1; yt:=1; xo:=1; yo:=1; r:=2;z:=0;z1:=0; randomize; d:=detect;initgraph(d, m, ''); setcolor(yellow); setbkcolor(blue); for TX:=1 to 3 do for TY:=1 to 4 do rectangle(TX*50,TY*50,TX*50+35,TY*50+35);rectangle(35,35,201,251); repeat 1:if S=2 then r:=random(3)+1; if S=3 then r:=random(3)+2; if S=4 then begin r:=random(3)+1; case r of 1:r:=1; 2:r:=3; 3:r:=4;end; end; if s=1 then begin r:=random(3)+1; case r of 1:r:=1; 2:r:=2; 3: r:=4; end; end; case r of 1 : if XT>1 then Dec(XT);2 : if YT<5 then Inc(YT); 3 : if XT<4 then Inc(XT);4 : if YT>1 then Dec(YT); end; if (X=1) and (Y=1) and (r=2) then goto 2; if (x=3) and (y=3) then z:=z+1 ; if (X=XT) and (Y=YT) then goto 1; X:=XT; Y:=YT; S:=r; if S=1 then begin for T:=XO*50 downto X*50 do begin setcolor(15);circle(T-7,Y*50-6,5);delay(10); setcolor(0);circle(T-7,Y*50-6,5); setcolor(green);circle(142,142,5);end;end; if S=2 then begin for T:=YO*50 to Y*50 do begin setcolor(15);circle(X*50-7,T-6,5);delay(10); setColor(0);circle(X*50-7,T-6,5);setcolor(green);circle(142,142,5);end;end; if S=3 then begin for T:=XO*50 to X*50 do begin SetColor(15);Circle(T-7,Y*50-6,5);Delay(10); SetColor(0);Circle(T-7,Y*50-6,5);setcolor(green);circle(142,142,5);end;end; if S=4 then begin for T:=YO*50 downto Y*50 do begin setcolor(15);circle(X*50-7,T-6,5);delay(10); setcolor(0);circle(X*50-7,T-6,5);setcolor(green);circle(142,142,5);end; end; if (X=1) and (Y=5) and (S=4) then goto 2; XO:=X; YO:=Y; until keypressed; 2:closegraph; if (z=0) and (z1=0) then writeln('They have never been to cafe') else begin if z>z1 then begin prots:=(z1*100)/z; Writeln('1st tourist was ',z,' times in this cafe'); Writeln('2nd tourist was ',z1,' times in this cafe'); Writeln('They meet each other in cafe in ',prots:5,' % of their being in cafe at all'); end else begin prots:=(z*100)/z1; Writeln('1st tourist was ',z,' times in this cafe'); Writeln('2nd tourist was ',z1,' times in this cafe'); Writeln('They meet each other in cafe in ',prots:5,' % of their being in cafe at all'); end; end; 3:readkey; clrscr; end.