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

popel
New poster
Posts: 33
Joined: Fri Mar 15, 2002 2:00 am
Location: Dhaka, Bangladesh
Contact:

Post by popel »

Larry wrote:Once again, use long long...

Code: Select all

4000000000
should yield

Code: Select all

1 4000000004
*. At first Thank you. Because your answer pointed my my mistake

*. Is 4000000004 a long long ? Unsigned long is enough here.
So one should not use long long.....(its slower)

*. So silly I am ! I couldn't find the normal case :oops:
that I used unsigned int in my code first but :
[c]printf("%d %d\n");[/c]

______________________________________________Md.Tanvir Al Amin

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am

Problem 10018

Post by Red Scorpion »

You must notice that palindrome numbers <= 4294967295,

and you should use unsigned long integer to stor that value.

try this test cases :

Input:
2
2
99
Output:
1 4
6 79497

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am

Probelm 10018

Post by Red Scorpion »

You should notice that palindromes numbers <=4294967295,
and try to use unsigned long integer.

Try this test cases :
Input:
2
2
99
Output:
1 4
6 79497

Taslim
New poster
Posts: 9
Joined: Sun Dec 08, 2002 11:47 am
Contact:

I got AC 10018

Post by Taslim »

Hi Red Scorpion thanks for ur replay .. I got Ac :) atlast ... But the problem was not there....My program give same out put for your given sample input.
Thanks to all and thank you again my frined. 8)

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

You're right, they made it so that it'll fit in an unsigned int.

I just feel safer with long long, so I can check invalid inputs easier (very common in these contests..) with an inequality..

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok »

Probably it's the last printf statement ... try to use %u instead of %ld ...

-turuthok-
The fear of the LORD is the beginning of knowledge (Proverbs 1:7).

JiaYun
New poster
Posts: 12
Joined: Thu May 01, 2003 4:27 am

10018 WA

Post by JiaYun »

I hava tested this input

Code: Select all

6
195
265
750
2
99
4000000000
and the output is:

Code: Select all

4 9339
5 45254
3 6666
1 4
6 79497
1 4000000004
It's still WA..... :cry:

[java]deleted
[/java]
Last edited by JiaYun on Sat Jun 19, 2004 8:16 am, edited 1 time in total.

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

This problem is kind of funny. The first time I submitted it I got AC, but a month later the judge mailed me a new verdict WA. I corrected it for numbers that are already palindrome such as 99, the answer is 0 99.

But later I got another verdict saying that the original solution is correct. The problem may be in such numbers. :-?

JiaYun
New poster
Posts: 12
Joined: Thu May 01, 2003 4:27 am

Post by JiaYun »

I modified the code. Now, the ouput is

Code: Select all

4 9339
5 45254
3 6666
0 2
0 99
1 4000000004
But it's still WA.... :cry:

Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

hello JiaYun....

My AC code give same result with your first I/O, not your second I/O

Code: Select all

4 9339
5 45254
3 6666
1 4
6 79497
1 4000000004
and when I submit my code when my answer like your second I/O, I got WA after new judge. :)

JiaYun
New poster
Posts: 12
Joined: Thu May 01, 2003 4:27 am

Post by JiaYun »

so, what difference between your AC code and my first code :roll:

The judge fooled me. :cry:

Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

hello.... I'm sorry, I'm not familliar with java, I use C to solve this problem.

But I think the tricky input only if input is palindrome, you cannot output that. So there aren't output with count 0.

Maybe your mistake only in input or output, not your algo. Because some people WA because of that.

JiaYun
New poster
Posts: 12
Joined: Thu May 01, 2003 4:27 am

Post by JiaYun »

Thank you. I will reconsider it when I recover from the beat. :o :P

Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm

10018

Post by Almost Human »

I don't get it. Why did I get WA ????

Any sugesstion ???

Code: Select all

#include <stdio.h>
#include <string.h>

unsigned long reverse ( unsigned long ) ;

int main ( void )
{
  unsigned long input , addition ;
  int iteration , NumOfCase ;
  char temporary[100] ;

/*  freopen ( "10018.in" , "r" , stdin ) ;
  freopen ( "10018.out" , "w" , stdout ) ;*/

  scanf ( "%i" , &NumOfCase ) ;

  while ( NumOfCase -- )
  {
	 scanf ( "%li" , &input ) ;

	 addition = reverse ( input ) ;
	 for ( iteration = 0 ; ; )
	 {
		input += addition ; iteration ++ ;
		addition = reverse ( input ) ;
		if ( addition == input ) break ;
	 }
	 printf ( "%i %li\n" , iteration , input ) ;
  }

  return 0 ;
}

unsigned long reverse ( unsigned long torev )
{
  unsigned long rev = 0 ;

  while ( torev )
  {
	 rev = rev * 10 + torev % 10 ;
	 torev /= 10 ;
  }

  return rev ;
}
Any sample input and output ???

thanks

Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

use %lu for unsigned long instead of %li.

Post Reply

Return to “Volume 100 (10000-10099)”