Why this doesn't work?? (1002)
Can you tell me why this doesn't work???
Here is my code:
***********************************************************
program third;
const
dict : array['a'..'z'] of char = ('2','2','2','3','3','3','4','4','1','1','5','5','6','6','0','7','0','7','7','8','8','8','9','9','9','0');
type str = array[1..50000] of string;
str2 = array[1..100] of string;
var num,Answer : string;
numOfWords,i,j : longint;
Word,Tran : str;
Solution : str2;
min,k : integer;
real : array[1..100] of string;
function isEmpty(s : string) : boolean;
var i : longint;
ok : boolean;
begin
ok := true;
for i := 1 to length(s) do
if s[i] <> ' ' then ok := false;
isEmpty := ok;
end;
function translate(q : string) : string;
var s : string;
i : longint;
begin
s := '';
for i := 1 to length(q) do s := s + dict[q[i]];
translate := s;
end;
procedure FindSmallest(s : string;n : longint;sol : str2;br : integer);
var i,p,q : longint;
s1 : string;
begin
if isEmpty(s) then begin
if br-1 < min then begin
for i := k to k+br-1 do Real[i] := sol[i];
min := br-1;
end;
end
else
for i := 1 to n do begin
s1 := s;
p := pos(tran[i],s1);
if p > 0 then begin
sol[br] := word[i];
delete(s1,p,length(word[i]));
insert(' ',s1,p);
FindSmallest(s1,n,sol,br + 1);
end;
end;
end;
begin
k := 1;
readln(num);
while num <> '-1' do begin
min := maxint;
readln(numOfWords);
for i := 1 to numOfWords do begin
readln(word[i]);
for j := 1 to length(word[i]) do
tran[i] := translate(word[i]);
end;
FindSmallest(num,numOfWords,Solution,1);
if min <> maxint then begin
inc(min);
real[min] := ' ';
inc(k,min);
end
else begin
real[k] := 'No';
inc(k);
real[k] := 'solution.';
inc(k);
real[k] := ' ';
end;
readln(num);
end;
for i := 1 to k-2 do begin
if real[i] = ' ' then writeln
else if real[i+1] = ' ' then write(real[i])
else write(real[i],' ');
end;
write(real[k-1]);
writeln;
end.
**********************************************************
It fails on 1st....
Thank you!
Edited by author 17.04.2008 01:54
Edited by author 17.04.2008 01:55