1040. Longest Symmetric String (25)
#include <stdio.h>
#include <string.h>
class CA
{
public:
enum{len=1000};
void run();
char snum[len];
};
void CA::run()
{
gets(snum);
int l=strlen(snum);
int i,j,mid,sym,maxSym=1;
mid=1;
while(mid<l)
{
i=mid-1;j=mid+1;
sym=1;
while (i>=0&&j<l&&snum[i]==snum[j])
{
sym+=2;
i--;j++;
}
if(sym>maxSym) maxSym=sym;
mid++;
}
mid=1;
while(mid<l)
{
i=mid-1;j=mid;
sym=0;
while (i>=0&&j<l&&snum[i]==snum[j])
{
sym+=2;
i--;j++;
}
if(sym>maxSym) maxSym=sym;
mid++;
}
printf("%d\n",maxSym);
}
int main()
{
// freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}