ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1002. Phone Numbers

why am i wrong in test#10?
Posted by zhujy 2 Apr 2008 20:32
program u1002;
const
 di: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');
 maxl=1 shl 30-1;
var
 pre,f:array[0..100]of longint;
 tt,s,t,ss,no:string;
 i,j,n,l:longint;
 ans:array[0..100,0..100]of string;
 dp:array[0..100,0..100]of boolean;
procedure print(l,r:longint);
 begin
  if l-1<>0 then print(pre[l-1],l-1);
  write(ans[l,r-l+1],' ');
 end;
begin
  readln(s);
  while s<>'-1' do begin
   for i:=0 to length(s)do f[i]:=maxl; f[0]:=0;
   fillchar(dp,sizeof(dp),0);
   fillchar(pre,sizeof(pre),0);
   readln(n); f[0]:=0;
  for i:=1 to n do begin
   ss:=s; readln(t); l:=length(t);
    tt:=t;        no:='';
   for j:=1 to l do begin t[j]:=di[t[j]];  no:=no+' ' end;
   j:=pos(t,ss);
   while j<>0 do begin
    dp[j,l]:=true; ans[j,l]:=tt;
    delete(ss,j,l);  insert(no,ss,j);
    j:=pos(t,ss)
   end;
   end;
   for i:=1 to length(s)do
  for j:=i downto 1 do
    if dp[j,i-j+1]and(f[j-1]<>maxl)and(f[j-1]+1<f[i])then  begin
   f[i]:=f[j-1]+1; pre[i]:=j;    end;
   if f[length(s)]=maxl then write('No solution.')
  else print(pre[length(s)],length(s));
    writeln;
   readln(s)
 end;
end.
Re: why am i wrong in test#10?
Posted by Viknet 4 Apr 2008 02:43
...
//delete(ss,j,l); insert(no,ss,j);
delete(ss,j,1); insert(' ',ss,j);
...