[r]
(1)Bài 39/2000 - Ô chữ
{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q+,R+,S-,T-,V+,X+} {$M 16384,0,655360}
uses crt;
const fi = 'input.txt'; fo = 'output.txt';
var A : array[1 5,1 5] of char; new,blank : record x,y : integer end; procedure no_no_and_no;
var f : text; begin
assign(f,fo); rewrite(f);
write(f,'This puzzle has no final configuration.'); close(f);
halt; end;
procedure yes_yes_and_yes; var f : text; i,j : byte; begin
assign(f,fo); rewrite(f); for i := to begin
for j :=1 to write(f,a[i,j]); writeln(f); end;
close(f); end;
procedure swap(px,py : integer); var coc : char;
begin
new.x := blank.x + px; new.y := blank.y + py;
(2)coc := A[new.x,new.y];
A[new.x,new.y] := A[blank.x,blank.y]; A[blank.x,blank.y] :=coc;
blank := new; end;
procedure chuyen(ch : char); begin
case ch of
'A' : swap( -1,0); 'B' : swap( 1,0); 'R' : swap( 0, 1); 'L' : swap( 0,-1); end;
end;
procedure docf; var f : text; i,j : byte; s : string[5]; ch : char; begin
assign(f,fi); reset(f);
for i :=1 to begin
readln(f,s);
if length(s) = then s := s+ #32; for j := to
begin
A[i,j] := s[j]; if A[i,j] = #32 then begin
blank.x := i; blank.y := j; end;
end; end;
while not seekeof(f) begin
read(f,ch);
(3)chuyen(ch); end;
close(f); end;
BEGIN clrscr; docf;