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 WA?(C)
Posted by dubowen91 23 Jan 2008 22:24
1002:
#include<stdio.h>
#include<string.h>

char phone[110],word[50008][58],me[50008][58];
long leng[110],re[110],dp[110];
int tel[27]={0,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},
    number[10]={0,1,2,3,4,5,6,7,8,9};

 int compare (long i,long j,long k)
{
 if(tel[word[i][j]-'a'+1]!=number[phone[k]-'0']) return 0;
 if(j==0) return 1;
 return compare(i,j-1,k-1);
}

 int main()
{
 long i,j,n,k;
 int m;
 for(;scanf("%s",phone),phone[0]!='-';)
  {
   leng[0]=strlen(phone);
   for(i=leng[0];i>=1;i--)
    phone[i]=phone[i-1];
   scanf("%ld",&n);
   for(i=1;i<=n;i++)
    {
     scanf("%s",word[i]);
     leng[i]=strlen(word[i]);
     }
   for(i=1;i<=109;i++)
    dp[i]=2147483640;
   dp[0]=0;
   for(i=1;i<=leng[0];i++)
    for(j=1;j<=n;j++)
     {
      if(i>=leng[j])
       {
        m=compare(j,leng[j]-1,i);
        if((m==1)&&(dp[i-leng[j]]!=2147483640)&&(dp[i]>dp[i-leng[j]]+1))
         {
          dp[i]=dp[i-leng[j]]+1;
          re[i]=j;
         }
        }
       }
   k=leng[0];
   if(dp[leng[0]]==2147483640)
    printf("No solution.\n");
   else
    {
     for(i=1;;i++)
      {
       strcpy(me[i],word[re[k]]);
       k=k-leng[re[k]];
       if(k==0)
        break;
      }
      for(;i>1;i--)
       printf("%s ",me[i]);
      printf("%s",me[1]);
      printf("\n");
     }
    }
 return 0;
}


Thank you !
Re: why am I WA?(C)
Posted by Yashar Abbasov 24 Jan 2008 01:25
What did you fix in your code to get AC. where was your fault?
Re: why am I WA?(C)
Posted by dubowen91 25 Jan 2008 11:18
I never fix it !someone use my ID to check it!