## Problem J2: 9966

The digits 0, 1, and 8 look much the same if rotated 180 degrees on the page (turned upside down). Also, the digit 6 looks much like a 9, and vice versa, when rotated 180 degrees on the page. A multi-digit number may also look like itself when rotated on the page; for example 9966 and 10801 do, but 999 and 1234 do not.

You are to write a program to count how many numbers from a given interval look like themselves when rotated 180 degrees on the page. For example, in the interval [1..100] there are six : 1, 8, 11, 69, 88, and 96.

Your program should take as input two integers, m and n, which define the interval to be checked, 1 ≤ mn ≤ 32000. The output from your program is the number of rotatable numbers in the interval.

You may assume that all input is valid.

```1
100
```

### Sample Output

```6
```

Point Value: 3
Time Limit: 2.00s
Memory Limit: 16M

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

• (0/0)
I tested this out on my computer but it seemed to work. When I submitted this to the OJ it gave me an WA. :(

• (1/0)
You are not null-terminating reverse, hence your if (reverse == num) check will always fail.

• (2/2)
The sample input says the two numbers will be on the same line. I was getting RE so I tried inputs on separate lines and it worked. The sample information can throw people off.

• (3/0)
Fixed

• (0/0)
Any hint why my latest submission for this question is wrong? My code passed all test cases offline. But it got all wrong answers here. Any hint?

• (1/7)
print "The number of rotatable numbers is:" before printing the actual answer...

• (0/0)
Test data links were broken, probably due to a change in the server's file structure. It's fixed now, and submissions are rejudged.

• (0/0)
Is not the two input integers should be on the same line? Just as the Sample Input?

• (0/0)
In the actual input, the two integers may be on different lines.

• (1/0)

 Specifically, you seem to have assumed that m and n will always be given on a single line, whereas in fact the problem statement does not guarantee this, and it's possible for them to be given on different lines.

• (0/1)
A small question:
would the number 80 be classified as rotatable? you could represent it as 080?

• (0/0)
Interesting idea, but nope. Just do a regular check of the given number.

• (2/0)
 For example, in the interval [1..100] there are six : 1, 8, 11, 69, 88, and 96.
In programming problems, unless explicitly stated otherwise, leading zeroes are not allowed in numbers.

• (0/0)
I checked a lot of test cases which I verified by hand and I'm getting all the correct answers. However, when I submit my program, all the test cases return "Exception_in_thread_..." What exactly does this refer to? Thanks.

• (1/0)
That's a runtime error; an exception occurred, meaning something unexpected went wrong. Sadly Java happens to be very verbose, so that the part of the message that actually tells you what you did wrong was cut off. You got a NoSuchElementException in java.util.StringTokenizer, which means an error occurred while parsing input. Specifically, you seem to have assumed that m and n will always be given on a single line, whereas in fact the problem statement does not guarantee this, and it's possible for them to be given on different lines. Consider using java.util.scanner instead.

• (0/0)
Thanks a lot Brian! I knew that an exception occurred, I just didn't know where or which exception occurred because the output ended with "..."

Thanks again for your help :).

• (0/0)
How do people do this question? It's hard. Help? (I can't believe this question's worth 3 points. Some people say it's the hardest 3-point question they've ever done)

• (0/0)
It's rather simple once you think about it.
Simply [redacted]. That specifically is probably the hardest part, but there are many ways you can do it.

• (0/0)
Thank you.