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 not?! WA on test 3. Delphi/Pascal
Posted by Martinez 7 Dec 2010 13:38
My code is:

{$apptype console}
uses
  sysutils;
var
  number:string[100];
  buf,buf2:string;

  i,n,k:0..50000;
  a:array[1..100,1..2]of string; //ñëîâàðü
  b:array['a'..'z'] of char;
procedure set_b;
begin
  b['i']:='1'; b['j']:='1';
  b['a']:='2'; b['b']:='2'; b['c']:='2';
  b['d']:='3'; b['e']:='3'; b['f']:='3';
  b['g']:='4'; b['h']:='4';
  b['k']:='5'; b['l']:='5';
  b['m']:='6'; b['n']:='6';
  b['p']:='7'; b['r']:='7'; b['s']:='7';
  b['t']:='8'; b['u']:='8'; b['v']:='8';
  b['w']:='9'; b['x']:='9'; b['y']:='9';
  b['o']:='0'; b['q']:='0'; b['z']:='0';
end;
procedure translation;
begin
for k:=1 to n do
  begin
    setlength(a[k,2],length(a[k,1]));
    for i:=1 to length(a[k,2]) do
    a[k,2,i]:=b[a[k,1,i]];
  end;
end;
procedure seeking(f:integer);
var i,leng,leng2:integer;
begin
  i:=1;
  while (i<=n)and(buf2<>number) do
  begin
  if pos(a[i,2],number)=f
  then
    begin
      leng:=length(buf);
      leng2:=length(buf2);
      buf:=buf+a[i,1]+' ';
      buf2:=buf2+a[i,2];
      if buf2<>number then
      seeking(f+length(a[i,1]));
      if buf2<>number then
      begin
      setlength(buf,leng);
      setlength(buf2,leng2);
      end;
    end;
  inc(i);
  end;
end;
begin
  set_b;
  repeat
  buf:='';
  buf2:='';
  readln(number);
  if number='-1' then exit;
  readln(n);
  for i:=1 to n do
      readln(a[i,1]);
  translation;
  seeking(1);
  if buf2=number then
  writeln(buf)
  else writeln('No solution.')
  until false;
end.