4 / 4
Feb 2020
#include<iostream>
#include<cmath>
#define ll unsigned long long
using namespace std;
int ispalindrome(ll int a)
{
    ll int temp=a;
    int n=0;
    while(temp){temp/=10;n++;}
    int arr[n];
    for(int i=0;i<n;i++)
    {
        arr[n-i-1]=a%10;
        a/=10;
    }
    int flag=0;
    for(int i=0;i<n/2;i++)
    {
        if(arr[n-i-1]!=arr[i])
        {
            flag++;break;
        }
    }
    if(flag==0){return 1;}
    else{return 0;}
}
int main()
{
    int test;cin>>test;
    while(test--)
    {
        ll int n;cin>>n;
        ll int i=1;
        while(1)
        {
            if(ispalindrome(n+i)==1){cout<<n+i<<endl;break;}
            i++;
        }
    }
}

I have tried a lot of test cases. Where have I gone wrong?

  • created

    Feb '20
  • last reply

    Feb '20
  • 3

    replies

  • 665

    views

  • 2

    users

Here. Like many others before you, you’ve misread the constraints.

Check the maximum size of the integer again. It is not one million, and is far too large to fit in an unsigned long long int.