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 1297. Palindrome

WHY WA ON TEST #2??? I CAN'T UNDERSTAND
Posted by michel mizrahi 17 May 2005 07:58
I think my code is correct..
what's the tricky input? or what's wrong with my code?
I just made a O(n^2) algorithm to search
here is my code:
#include <stdio.h>
#include <string.h>
char a[1003],b[1003];

int main(){
  int i,j,u,v,l,ind,res=0,tmp;
  scanf("%s",&a);
  l=strlen(a);
  for(i=0;i<l;i++)
    b[i]=a[l-1-i];
  for(i=0;i<l;i++)
    for(j=0;j<l;j++)
      if(a[i]==b[j]){
         tmp=0;
         for(u=i+1,v=j+1;v<l;u++,v++){
            if(a[u]==b[v])
              tmp++;
            else
              break;
         }
         if(tmp>=res){
           res=tmp;
           ind=i;
         }
     }
   for(i=ind;i<=ind+res;i++)
      printf("%c",a[i]);
   printf("\n");
  return 0;
}
If there are several, choose the leftmost; a test for you (+)
Posted by Michael Rybak (accepted@ukr.net) 11 Feb 2006 00:24
AB

your answer: B
correct answer: A