program psp;

var
   cword,eword,aword,fword:string;
   file:text;
   num:integer;
   cnum,enum,fnum:integer;
   i:integer;


procedure sread(var s:string);
var
   c:char;
   a:integer;

begin
a:=1;
s:='';
repeat
 c:=inkey;
 if c=chr(8) then begin
  if a>1 then begin
   a:=a-1;
   write(' ',c);
   write(c);
   write(' ',c);
  end;
 end
 else
  begin
   s[a]:=c;
   write(c);
   a:=a+1;
  end;
until c=chr(13);
s[0]:=chr(a-2);
writeln;
end;

begin
writeln(' ================ PSP =================');
writeln('    Primitivni Slovnik pro Portfolio');
writeln(' ========== BaR design 1998 ===========');
assign(file,'words.dat');
repeat
 reset(file);
 readln(file,num);
 write(' ? ');
 sread(aword);
 for i:= 1 to num do
 begin
  cword:='*';
  readln(file,fword);
  fnum:=length(fword);
  cnum:=pos(cword,fword);
  copy(cword,fword,1,cnum-1);
  copy(eword,fword,cnum+1,fnum-cnum);
  if aword = cword then writeln(' > ',eword);
  if aword = eword then writeln(' > ',cword); 
 end;
until aword=''; 
close(file);
end.
