1 / 3
Apr 2020

What am I doing wrong, I can’t figure it out.

#include <iostream>
    using namespace std;

    bool palCheck(int a)
    {
        int x=a,aux=0;
        while(a)
        {
            aux=aux*10+a%10;
            a=a/10;
        }
        if(aux==x)
            return true;
        else
            return false;
    }

    int nextPal(int a)
    {
        while(palCheck(a)!=true)
            a++;
        return a;
    }

    int main()
    {
        int n, x, i=1, f;
        cin>>n;
        f=n;
        int v[n+1];
        while(f)
        {
            cin>>x;
            x++;
            v[i]=nextPal(x);
            i++;
            f--;
        }
        for(i=1;i<=n;i++)
            cout<<v[i]<<'\n';
        return 0;
    }
  • created

    Apr '20
  • last reply

    Apr '20
  • 2

    replies

  • 580

    views

  • 2

    users

Re-read the problem description, and check the max size of the integer.

Thanks man, I read it again and this time I noticed that it actually said that K has maximum 1000000 digits. Still though, does that mean that I should use a string? I’m really confused.