Two similar codes - diffirent results
Послано
maksay 1 дек 2007 00:00
Var s:string;
t,r:array[1..50000] of string;
m:array[0..150] of longint;
n,i,j:Longint;
ex:boolean;
Procedure dfs(v:longint);
Var i,l:Longint;
begin
if v=length(s) then begin ex:=true;Exit; end;
i:=1;While (i<=n) {and (not ex)} do
begin
l:=length(t[i]);
if Copy(s,v+1,l)=t[i] then
begin
m[v+l]:=i;
dfs(v+l);
end;
Inc(i);
end;
end;
Procedure papa(v,p:longint);
begin
if v=0 then Exit;
papa(v-length(t[m[v]]),v);
Write(r[m[v]]);
if p<>0 then Write(' ') else Writeln;
end;
begin
Readln(s);
While (s<>'-1') and (not eof) do
begin
Readln(n);
For i:=1 to n do
begin
Readln(r[i]);
t[i]:='';
For j:=1 to length(r[i]) do
if (r[i,j]='i') or (r[i,j]='j') then t[i]:=t[i]+'1' else
if (r[i,j]='a') or (r[i,j]='b') or (r[i,j]='c') then t[i]:=t[i]+'2' else
if (r[i,j]='d') or (r[i,j]='e') or (r[i,j]='f') then t[i]:=t[i]+'3' else
if (r[i,j]='g') or (r[i,j]='h') then t[i]:=t[i]+'4' else
if (r[i,j]='k') or (r[i,j]='l') then t[i]:=t[i]+'5' else
if (r[i,j]='m') or (r[i,j]='n') then t[i]:=t[i]+'6' else
if (r[i,j]='p') or (r[i,j]='r') or (r[i,j]='s') then t[i]:=t[i]+'7' else
if (r[i,j]='t') or (r[i,j]='u') or (r[i,j]='v') then t[i]:=t[i]+'8' else
if (r[i,j]='w') or (r[i,j]='x') or (r[i,j]='y') then t[i]:=t[i]+'9' else
t[i]:=t[i]+'0';
end;
For i:=1 to length(s) do m[i]:=-1;ex:=false;m[0]:=0;dfs(0);
if n=0 then Writeln('No solution.') else
if length(s)=0 then Writeln else
if ex then papa(length(s),0) else
Writeln('No solution.');Readln(s);
end;
end.
This code gets WA3, but if i remove comments {and (not ex)} then i've got TL5 - its easy yo understand...but wy small change makes WA?!!