Page 11 of 12

Re: 10018 - Reverse and Add

Posted: Fri May 24, 2013 11:43 pm
by hoimo
Why WA? my code is correct for all possible input.

please help.

code removed after AC

Re: 10018 - Reverse and Add

Posted: Sat May 25, 2013 2:28 am
by brianfry713
Try using long long instead of long, and atoll instead of atoi.

Re: 10018 - Reverse and Add

Posted: Sat May 25, 2013 5:31 pm
by hoimo
yes i got it. atol made it. thank you very much.

Re: 10018 - Reverse and Add

Posted: Mon Nov 04, 2013 10:17 am
by blackheartadhar
Removed! After Accepted!

Re: 10018 - Reverse and Add

Posted: Tue Nov 05, 2013 12:55 am
by brianfry713
Doesn't match the sample I/O.

Re: 10018 - Reverse and Add

Posted: Mon Nov 25, 2013 10:46 am
by bimajw
Accepted

Re: 10018 - Reverse and Add

Posted: Tue Nov 26, 2013 2:35 am
by brianfry713
Try using long long instead of long

Re: 10018 - Reverse and Add

Posted: Tue Nov 26, 2013 6:25 am
by bimajw
thanks brianfry713 :D
i got AC

Re: 10018 - Reverse and Add

Posted: Mon Jul 28, 2014 11:18 am
by Shahidul.CSE
Why WA with my code?

Code: Select all

Code Removed after Accepted

Re: 10018 - Reverse and Add

Posted: Mon Jul 28, 2014 2:03 pm
by lbv
Shahidul.CSE wrote:Why WA with my code?
Try:

Input

Code: Select all

1
123789
Output

Code: Select all

2 1222221

Re: 10018 - Reverse and Add

Posted: Mon Jul 28, 2014 2:20 pm
by lighted
You must check input in this thread first.
Adrian Kuegel wrote:Try this testcase:
Input:
2
2
99
Output:
1 4
6 79497
You must repeat "reverse and add" method at least once and then check if it is a palindrome.
This is statement is wrong.
1)If n is already pallindrome, output is 0 n

Re: 10018 - Reverse and Add

Posted: Mon Jul 28, 2014 5:13 pm
by Shahidul.CSE
Thank you lighted and lbv.
Got accepted ! :D :D

Re: 10018 - Reverse and Add

Posted: Mon Jul 28, 2014 9:29 pm
by lbv
lighted wrote:You must check input in this thread first. (..)
This is statement is wrong.
My AC program produces:

Input

Code: Select all

2
2
99
Output

Code: Select all

0 2
0 99
So it seems that the statement "If n is already pallindrome, output is 0 n" (which Shahidul.CSE may have inferred from previous test cases posted in these forums) is not wrong. It may be the case that the judge's data sets don't contain cases in which the number is a palindrome from the start.

Re: 10018 - Reverse and Add

Posted: Tue Jul 29, 2014 8:24 pm
by brianfry713
The first line in the problem statement:
The "reverse and add" method is simple: choose a number, reverse its digits and add it to the original. If the sum is not a palindrome (which means, it is not the same number from left to right and right to left), repeat this procedure.

You should repeat the method at least once, but there are no inputs where P is a palindrome in the judge's input, so you'll get AC either way.

Re: 10018 - Reverse and Add

Posted: Tue Jan 06, 2015 10:25 am
by battirunner
Getting Compile error in ANSI C.... which can be the problem ? anyone help plzzz....

Code: Select all

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int itaration,test;
unsigned int number1,number2;
char num1[50],num2[50];
scanf("%d",&test);
getchar();

while(test--)
{
    gets(num1);
    itaration=0;
    while(1)
    {

    itaration++;
    strcpy(num2,num1);
    strrev(num2);
   number1=atoi(num1);
   number2=atoi(num2);
   number1=number1+number2;
   itoa(number1,num1,10);
   strcpy(num2,num1);
   if(!strcmp(num1,strrev(num2)))
   {

    printf("%d %s\n",itaration,num1);
    break;
   }

    }

}

return 0;
}