include
using namespace std;
int palindrome(float x){
int reverse=0,temp;
temp=x;
while(temp!=0){
reverse=reverse*10;
reverse=reverse+temp%10;
temp=temp/10;
}
if(x==reverse)
return 1;
else
return 0;
}
int main(){
int t,ans;
float K;
cin>>t;
while(t--){
cin>>K;
do{
ans=palindrome(K);
if(ans==1)
break;
K++;
}while(ans!=1);
cout< }
return 0;
}
(Last cout is K which is the next palindrome.)
Im given Time limit exceeded error for the above code, please help me to point out how to reduce the time required for running. Suggestions are welcomed.
By the way the code is alright. U might have to understand few lines because this post is not exactly posting the same code as of mine.
Thanks.
created
last reply
- 3
replies
- 1.1k
views
- 2
users
- 2
links