10018 - Reverse and Add

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

hoimo
New poster
Posts: 18
Joined: Sun Sep 23, 2012 3:43 am

Re: 10018 - Reverse and Add

Post by hoimo » Fri May 24, 2013 11:43 pm

Why WA? my code is correct for all possible input.

please help.

code removed after AC
Last edited by hoimo on Mon Dec 16, 2013 3:54 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10018 - Reverse and Add

Post by brianfry713 » Sat May 25, 2013 2:28 am

Try using long long instead of long, and atoll instead of atoi.
Check input and AC output for thousands of problems on uDebug!

hoimo
New poster
Posts: 18
Joined: Sun Sep 23, 2012 3:43 am

Re: 10018 - Reverse and Add

Post by hoimo » Sat May 25, 2013 5:31 pm

yes i got it. atol made it. thank you very much.

blackheartadhar
New poster
Posts: 10
Joined: Mon Nov 04, 2013 10:14 am

Re: 10018 - Reverse and Add

Post by blackheartadhar » Mon Nov 04, 2013 10:17 am

Removed! After Accepted!
Last edited by blackheartadhar on Wed Nov 06, 2013 8:32 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10018 - Reverse and Add

Post by brianfry713 » Tue Nov 05, 2013 12:55 am

Doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!

bimajw
New poster
Posts: 6
Joined: Wed Nov 14, 2012 5:26 am

Re: 10018 - Reverse and Add

Post by bimajw » Mon Nov 25, 2013 10:46 am

Accepted
Last edited by bimajw on Tue Nov 26, 2013 6:46 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10018 - Reverse and Add

Post by brianfry713 » Tue Nov 26, 2013 2:35 am

Try using long long instead of long
Check input and AC output for thousands of problems on uDebug!

bimajw
New poster
Posts: 6
Joined: Wed Nov 14, 2012 5:26 am

Re: 10018 - Reverse and Add

Post by bimajw » Tue Nov 26, 2013 6:25 am

thanks brianfry713 :D
i got AC

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10018 - Reverse and Add

Post by Shahidul.CSE » Mon Jul 28, 2014 11:18 am

Why WA with my code?

Code: Select all

Code Removed after Accepted
Last edited by Shahidul.CSE on Mon Jul 28, 2014 5:11 pm, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 10018 - Reverse and Add

Post by lbv » Mon Jul 28, 2014 2:03 pm

Shahidul.CSE wrote:Why WA with my code?
Try:

Input

Code: Select all

1
123789
Output

Code: Select all

2 1222221

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10018 - Reverse and Add

Post by lighted » Mon Jul 28, 2014 2:20 pm

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
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10018 - Reverse and Add

Post by Shahidul.CSE » Mon Jul 28, 2014 5:13 pm

Thank you lighted and lbv.
Got accepted ! :D :D
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: 10018 - Reverse and Add

Post by lbv » Mon Jul 28, 2014 9:29 pm

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.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10018 - Reverse and Add

Post by brianfry713 » Tue Jul 29, 2014 8:24 pm

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.
Check input and AC output for thousands of problems on uDebug!

battirunner
New poster
Posts: 14
Joined: Fri Aug 15, 2014 3:48 pm

Re: 10018 - Reverse and Add

Post by battirunner » Tue Jan 06, 2015 10:25 am

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;
}

Post Reply

Return to “Volume 100 (10000-10099)”