I wrote a program which finds the next palindrome. First, it takes an input specifying the number of test cases. The code runs fine in Visual C++, but am not able to run it in GCC.
I have never used GCC before so unaware with its functioning. But am expecting a standard code should run in all the standard compilers. I'm submitting the solution on a website. What option should I select, C++(gcc-4.0.0-8) or C++(gcc-4.3.2)?
#include<iostream>
using namespace std;
int palnext(char *);
int main()
{
char input[100000];
int n;
cin>>n;
while(n!=0)
{
cin>>input;
palnext(input);
n--;
cout<<input<<"\n";
}
cin.get();
cin.get();
return 0;
}
int palnext(char* a)
{
int half,temp,j=0,i=0;
while(a[i]!='\0')
i++;
half=i/2;
int flag=1,flag2=1;
temp=i-1;
while(j<half)
{
flag=1;
while(a[j]>a[temp])
{
flag2=0;
a[temp]++;
}
while(a[j]<a[temp])
{
if(flag)
{
a[temp-1]++;
flag=0;
}
flag2=0;
a[temp]--;
}
j++;
temp--;
}
if(flag2)
{
if(i%2==0)
{
a[half]++;
a[half+1]++;
}
else
a[half]++;
}
return 0;
}
Is it C99strict? Also, any suggestions regarding code optimization is also welcome.