Sunday, 29 September 2013

The Next palindrome

The Next palindrome

I am tryting to solve this next palindrome problem using
C++(http://www.spoj.com/problems/PALIN/) Even after getting the answer
correctly on my compiler I am getting a wrong answer on spoj.Even if
somebody could tell me any test case where this program fails will be
greatly useful.
#include<iostream>
#include<cmath>
using namespace std;
bool palin(int a)
{
int rev=0,d=a;
while(a!=0)
{
rev=(rev*10)+(a%10);
a=a/10;
}
if(rev==d)
{return true;}
else
{return false;}
}
int main()
{
int t;
cin>>t;
int c[t];
for(int i=0;i<t;i++)
{
int a;
cin>>a;
a++;
while(!palin(a))
{
a++;
}
c[i]=a;
}
cout<<endl;
for(int i=0;i<t;i++)
{cout<<c[i]<<endl;}
return 0;
}

No comments:

Post a Comment