CCC '00 J2 - 9966

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2000 Stage 1, Junior #2

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 10\,801 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 \dots 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 \le m \le n \le 32\,000. The output from your program is the number of rotatable numbers in the interval.

You may assume that all input is valid.

Sample Input

1
100

Sample Output

6

Comments


  • 2
    leoliu93233  commented on Feb. 11, 2024, 4:24 a.m.

    i swear 2000 is the hardest CCC junior


    • 1
      anjaneya  commented on Feb. 12, 2024, 3:26 a.m.

      fr


  • 1
    akhballett  commented on Feb. 1, 2024, 7:57 p.m.

    nice problem.


  • -3
    Kiki_Delfin  commented on Feb. 1, 2024, 7:52 p.m.

    The numbers are 1,6,8,9,0


    • 0
      akhballett  commented on Feb. 1, 2024, 7:58 p.m.

      redacted


  • -3
    960t  commented on Oct. 25, 2022, 2:59 a.m. edited

    does 2 and 5 work for this question? they do look somewhat similar...


    • 3
      lwale1  commented on Oct. 25, 2022, 4:52 p.m.

      No, only the numbers listed


      • 0
        960t  commented on Oct. 25, 2022, 10:39 p.m.

        thx


  • 3
    Korjwist  commented on Jan. 9, 2020, 12:14 a.m. edited

    My solution worked but it's way above the memory limit... How would one approach to reduce memory?


    • 1
      c  commented on Jan. 9, 2020, 5:16 a.m. edit 2

      In Java, the memory displayed is the total memory used by Java itself and your program. However, the memory limit is calculated internally based on what your program actually uses. Java itself takes around 24 megabytes for just "Hello, World!" If you had actually went over the memory limit, you would receive an MLE verdict.


  • 4
    Mark123  commented on Aug. 28, 2019, 10:26 p.m.

    What are the second, third and fourth test conditions? My code seems to work fine for any number I put in.


    • 14
      Tzak  commented on Aug. 28, 2019, 11:33 p.m. edited

      Try the following test case:

      8008
      8008

      The expected output is: 1


      • -1
        960t  commented on Oct. 28, 2022, 5:28 a.m.

        tysm :D


      • 7
        Mark123  commented on Aug. 29, 2019, 3:06 a.m.

        ty very much! I forgot 0 turned upside down is also a 0 smh...


  • -2
    yhashim_coding  commented on July 4, 2019, 8:16 p.m.

    I'm getting WA for the third and fourth test cases. Are there any conditions (my if/else statements) I missed (or applied to the wrong things)?


    • 1
      Sivart_Nap  commented on Sept. 28, 2020, 2:21 a.m.

      So am I, im not sure why though.


    • -2
      Dingledooper  commented on July 4, 2019, 9:35 p.m. edited

      At this for loop: for (int i = 0; i < aString.length()/2; i++){, the condition checks for the length of the string after every iteration, even if its size is changed.


      • -2
        yhashim_coding  commented on July 5, 2019, 8:10 p.m.

        Oh, I see. Is it possible to make it so that the for loop's condition is dynamic (changes each time)? As you can see in my code, it depends on the string shrinking and it's similar to recursion (although I think it's more simple). Is the only other way I can do it with this approach be using a recursive method?


  • -10
    Mackrel  commented on June 17, 2019, 4:40 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • 4
      Pleedoh  commented on June 17, 2019, 5:45 p.m.

      Your solution looks quite a bit over complicated my friend. Try to break it down into simpler conditions and test for each one.