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 algogeeks@googlegroups.com
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