NXTPALIN: Need help, getting wa

My code is as follows


 #include< stdio.h>
int main()
{
    long int t,k,i,j;
    scanf("%ld",&t);
    while(t--)
    {
        scanf("%ld",&k);
        for(j=k+1;k<=100001;j++)
        {
            int b,c=0;
            b=j;
            while (b>0)
            {
                c=c*10 +(b%10);
                b=b/10;
            }
            if(c==j)
            {
                printf("%ld\\n",j);
                goto exit;
            }
        }
        exit:;
    }
    return 0;
}

i ran the code over and over again to see what mistake i am doing.

still i am unable to find a bug.

I AM GETTING A WA on submission.

please help

1 Like

did you try to start from k instead of k+1 ? just in case…

Your code for

2
10
20

returns 11n22n.

1 Like

no, this forum does not handle ‘\’ correctly.
i edited the original poster to double-backslash it.

1 Like

the problem is you have to output the first palindrom number >= input.

you should make your loop starting from k instead of k+1.

3 Likes

I didn’t know that.

In statement (http://www.codechef.com/problems/NXTPALIN) there is that you have to find greater palindrome.

@cyberax is correct, the statement is not synchronized with test cases, start from K :wink:

thank you cyberax and betlista

This problem is from some peer contest and hence there could be some inconsistencies. Try http://www.codechef.com/problems/PALIN I think this doesn’t have any inconsistencies. This is bit more challenging as you have to work with strings.

ya i tried doing that problem but i haven’t succeeded till now :frowning: