Hi,
I think you have misread the problem. You are allowed to take away letters from 
the middle of the input string. So, for "ADAM", you have to check

AAM (D is removed)
ADM (A is removed)

in addition to the usual substrings (i.e. strings formed by taking away letters 
from the beginning or the end) that you are checking.
I hope this helps.

Muntasir 
  ----- Original Message ----- 
  From: mukesh tiwari 
  To: algogeeks digest subscribers 
  Sent: Friday, March 30, 2007 12:38 PM
  Subject: [algogeeks] getting wrong answer for problem


  hi friends i m trying to solve this problem
  http://acm.uva.es/p/v111/11151.html but getting wrong answer..
  my algorithm is ....i m trying to enumarate all the n*(n+1)/2 substrings  of 
string ,where n is string length... 
  and checking  for palindrom  ..
  suppose i have input ADAM .....then all possible substrings will be 
  ADAM
  ADA
  DAM
  AD
  DA
  AM
  A
  D
  A
  M
  now ADA is lagest palindrome ....
  but i don't know why i m getting WA... or plz tell me wheather my algorithm 
is right or wrong 

  here is my code .plz check it ..


  #include<stdio.h>
  #include<string.h>
   int chkpalin(char* a,int k,int n)
      {
          int w;
          for(w=k;w<=n;w++)
           if(a[w]!=a[n+k-w]) 
              return(0);
          
          return(1);
      }
      main()
       {

            char str[1010],c;
            int i,j,k,n,w,v;
              
           scanf("%d",&k);
           getchar(); 
          for(v=0;v<k;v++)
           {
              w=0;
              gets(str);
              n=strlen(str);
              for(i=n-1;i>=0;i--)
               {
                  for(j=0;j+i<n;j++)//enumarate all the n*(n+1)/2 substrings 
chk wheather a[j] to a[i+j] is palindrome or not 
                   {

                      w=chkpalin(str,j,i+j);
                      /*for(int x=j;x<=i+j;x++)
                       printf("%c",str[x]);
                       printf("\n");*/ 
                      if(w==1)
                       break;
                   }
                  
                  if(w==1)
                    break;
              }
              
              printf("%d\n",i+1); 
              /*for(int x=j;x<=i+j;x++)
                printf("%c",str[x]);
               printf("\n");*/
          }
      }


  

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to