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

Please give me some tests? on which my program is wrong! PROBLEM 1002
Posted by Reshetnikov Eugeny 24 Feb 2002 13:12
Only don's tell me about arrays size, because mistakes is not here...
This is my program:

Program t1002;
  Const  alp: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'
);
  Var  t              :string[100];
       s              :string[50];
       c,ans          :array [1..100,1..2] of longint;
       b              :array [1..10{0},1..50] of string[50];
       ok             :boolean;
       MaxLength      :byte;
       n,i,j,q,count,k:longint;

Procedure Entry;
  Begin
    For j:=1 to (Length(t)-Length(s)+1) Do
      If (s[1]=t[j]) or (alp[s[1]]=t[j]) Then
        Begin
          ok:=true;
          For q:=1 to Length(s) Do
            If (s[q]<>t[j-1+q]) and (alp[s[q]]<>t[j-1+q]) Then
              Begin
                ok:=false;
                Break;
              End;
          If ok Then
            b[j,Length(s)]:=s;
        End;
  End;

Procedure Solve(u:byte);
  Var  w:byte;
  Begin
    If k<count Then
      Begin
        If u>Length(t) Then
          Begin
            If k<count Then
              Begin
                count:=k;
                For i:=1 to count Do
                  Begin
                    ans[i,1]:=c[i,1];
                    ans[i,2]:=c[i,2];
                  End;
              End;
          End
        Else
          Begin
            For w:=MaxLength downto 1 Do
              If b[u,w]<>'' Then
                Begin
                  Inc(k);
                  c[k,1]:=u;
                  c[k,2]:=w;
                  Solve(u+w);
                  Dec(k);
                End;
          End;
      End;
  End;

Procedure Out;
  Begin
    If count=54321 Then
      WriteLn('No solution.')
    Else
      Begin
        For i:=1 to (count-1) Do
          Write(b[ans[i,1],ans[i,2]],' ');
        WriteLn(b[ans[count,1],ans[count,2]]);
      End;
  End;

Procedure Input;
  Begin
    While true Do
      Begin
        ReadLn(t); If t='-1' Then Halt;
        ReadLn(n);
        maxLength:=0;
        For i:=1 to Length(t) Do
          For j:=1 to 50 Do
            b[i,j]:='';
        While n>0 Do
          Begin
            Dec(n);
            ReadLn(s);
            If Length(s)>MaxLength Then
              MaxLength:=Length(s);
            Entry;
          End;
        count:=54321;
        k:=0;
        Solve(1);
        Out;
      End;
  End;

Begin
  Input;
End.
well, after me u'r program it's wrong... here's some input
Posted by Costel::icerapper@k.ro 24 Feb 2002 17:56
No subject
Posted by Costel::icerapper@k.ro 24 Feb 2002 17:57
INPUT:
Posted by Costel::icerapper@k.ro 24 Feb 2002 17:58
Well, when i try to submit 500 KB of input, the comments become empty... i'l try to put here a few tests
Posted by Costel::icerapper@k.ro 24 Feb 2002 17:59
2285064252258215
5
long
false
cat
tail
black
2285064252258219
5
long
false
cat
tail
black
1234567890
10
jafgl
n
ehlnr
tyz
ru
ja
iad
jadh
pty
yo
-1
Here is the correspunding output
Posted by Costel::icerapper@k.ro 24 Feb 2002 18:01
cat long black tail
No solution.
ja ehlnr tyz
May be you test my program with comments? sorry, if i'm wrong, but if i change array's size with 10 to 20 and string[50] change to string[30] my program gave right answers...
Posted by Reshetnikov Eugeny 24 Feb 2002 19:01
> cat long black tail
> No solution.
> ja ehlnr tyz