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

wa1?
Posted by zsyzzsx2 25 Jan 2010 17:55
I passed the test in the problem.
But why I couldn't pass the  first test?
Here are my program:
var
  s,s2:string;
  n,i,j,k,l:longint;
  s1,c:array[1..50000]of string;
  m:array[1..100,1..100]of integer;
  b:boolean;
function xun(len:longint):boolean;
  var
    j:longint;
  begin
    if j=1
    then begin
           xun:=true;
           exit;
         end;
    for j:=len-1 downto 1 do
      begin
        if m[j,len]>0
        then begin
               if xun(j)
               then begin
                      write(s1[m[j,len]],' ');
                    end;
             end;
      end;
  end;
begin
  //assign(input,'1002.in');reset(input);
  readln(s);
  repeat
  l:=length(s);
  readln(n);
  for i:=1 to n do
    begin
      b:=false;
      readln(s1[i]);
      for j:=1 to length(s1[i]) do
        case s1[i][j] of
          'i','j':c[i]:=c[i]+'1';
          'a','b','c':c[i]:=c[i]+'2';
          'd','e','f':c[i]:=c[i]+'3';
          'g','h':c[i]:=c[i]+'4';
          'k','l':c[i]:=c[i]+'5';
          'm','n':c[i]:=c[i]+'6';
          'p','r','s':c[i]:=c[i]+'7';
          't','u','v':c[i]:=c[i]+'8';
          'w','x','y':c[i]:=c[i]+'9';
          'o','q','z':c[i]:=c[i]+'0';
        end;
      for j:=1 to l-length(c[i])+1 do
        begin
          s2:=copy(s,j,length(c[i]));
          if s2=c[i]
          then m[j,j+length(c[i])-1]:=i;
        end;
    end;
    for j:=length(s)-1 downto 1 do
      begin
        if m[j,length(s)]>0
        then begin
               if xun(j-1)
               then begin
                      b:=true;
                      write(s1[m[j,length(s)]]);
                      break;
                    end;
             end;
      end;
    if b=false
    then write('No solution.');
    readln(s);
    writeln;
      fillchar(s1,sizeof(s1),0);
      fillchar(c,sizeof(c),0);
      fillchar(m,sizeof(m),0);
  until s='-1';
  //close(input);
end.