I am getting wrong answer for The next palindrome question( PALIN Problem - CodeChef ) even though I tried as many different cases I could think of.Here’s the code I used please suggest any more tricky cases for which this code is not working properly.Thanx in advance.
#include<iostream>
#include<string.h>
#define max 1000001
int main()
{
int cases,flag=0,looba=0;
long l,j,m;
char str[max];
scanf("%d",&cases);
for(int i=0;i<cases;i++)
{
scanf("%s",&str);
l=strlen(str);
for(j=0;j<l/2;j++)
{
if(str[j]!=str[l-j-1]&&l%2==0)
{
flag=1;
if(str[j]-str[l-j-1]<0&&j==0)
{
str[l-j-1]=str[j];
}
else if(str[j]-str[l-j-1]>0)
{
str[l-j-1]=str[j];
}
else
{
str[j]+=1;
str[l-j-1]=str[j];
}
}
else if(str[j]!=str[l-j-1]&&l%2!=0)
{
flag=1;
if(str[j]>str[l-j-1])
{
looba=1;
str[l-j-1]=str[j];
}
else
{
str[l-j-1]=str[j];
}
}
}
if(l%2!=0&&looba==0)
{
str[(l/2)]+=1;
}
else if(l%2==0&&flag==0)
{
str[l/2]+=1;
str[l/2-1]+=1;
}
printf("%s\n",str);
flag=0;
looba=0;
}
}