CCC '96 S2 - Divisibility by 11

View as PDF

Submit solution

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

Problem type
Allowed languages
ALGOL 68, Assembly, Brain****, C, C++, COBOL, Forth, Fortran, Java, Lua, Pascal, Text, Turing

Write a program which accepts as input a positive integer and checks, using the algorithm described below, to see whether or not the integer is divisible by 11. This particular test for divisibility by 11 was given in 1897 by Charles L. Dodgson (Lewis Carroll).

Algorithm:
As long as the number being tested has more than two digits, form a new number by:
  • deleting the units digit
  • subtracting the deleted digit from the shortened number
The remaining number is divisible by 11 if and only if the original number is divisible by 11.
Note:
Leading zeroes are not considered part of the number and should not be printed.

As usual, the first number in the input indicates the number of positive integers that follow. Each positive integer has a maximum of 50 digits. You may assume no leading zeroes exist in the positive integers.

For each positive integer in the input, the output consists of a series of numbers formed as a digit is deleted and subtracted, followed by a message indicating whether or not the original number is divisible by 11. Outputs for different positive integers are separated by blank lines.

Sample Input

2
12345678901234567900
10

Sample Output

12345678901234567900
1234567890123456790
123456789012345679
12345678901234558
1234567890123447
123456789012337
12345678901226
1234567890116
123456789005
12345678895
1234567884
123456784
12345674
1234563
123453
12342
1232
121
11
The number 12345678901234567900 is divisible by 11.

10
The number 10 is not divisible by 11.

Comments


  • 0
    duddo  commented on Nov. 27, 2023, 2:31 a.m.

    Why am I getting OLE?


  • -4
    Ronakße  commented on Feb. 16, 2022, 5:14 p.m.

    Can someone take a look at my code? I'm not sure why it's not working...


    • 0
      Spitfire720  commented on Feb. 19, 2022, 7:10 p.m.

      You have to print only 1 newline at the end.


  • 0
    13lack13lood  commented on Feb. 8, 2021, 12:09 a.m. edited

    how do you fix Presentation Error, check your whitespace?

    EDIT: you need only need one \n for the last output


  • 1
    xjhlg123555  commented on June 17, 2020, 2:07 a.m. edited

    Could someone please look at my last submission? I don't know what causes the WAs... Thanks

    Nvm I got it...The question should clarify that, if not divisible by 11, output "The number xxx is NOT divisible by 11."


  • -1
    Simon_Chase  commented on Oct. 30, 2019, 1:39 a.m. edited

    Could someone check my most recent submission? It ACs on the first test case but not on the next two, and I can't figure out why not. Any help would be appreciated!

    EDIT: forgot to check the final 2 digit number (ex. 22) lmao


  • 1
    Zafirua  commented on July 12, 2019, 4:34 p.m. edited

    Still cannot figure out what is the problem with my code -.- Can someone give me some hints as to what exactly I am doing wrong.


    • 10
      magicalsoup  commented on July 13, 2019, 1:06 a.m.

      you have to print the number again, so if the number was 121, you have to print

      121
      11
      The number 121 is divisible by 11.

      not

      11
      The number 121 is divisible by 11.

      which is what you are doing.


      • 0
        Jinx  commented on May 2, 2020, 11:02 p.m.

        THANKS SO MUCH! That was my problem too.


      • 2
        Zafirua  commented on Aug. 23, 2019, 3:54 a.m.

        My mistake, I really should read questions carefully. Thank you very much!


  • -3
    def_d  commented on Aug. 23, 2018, 10:28 p.m. edit 4

    This is a bit (a lot) harder because the input number is so long you can't put it all in one big int or long; the code will throw an InputMismatchException

    The memory limit is also super low

    Never mind this because the problem was edited some 22 years ago


  • 5
    1419903188  commented on Oct. 13, 2017, 9:57 p.m.

    DAMN

    I forgot "."

    ......


  • -2
    trollakatroll  commented on Jan. 19, 2017, 10:19 p.m.

    this question doesnt allow us to use bigdecimal or biginteger. how else are we supposed to hold such a big number? or can you allow to use bigdecimal or biginteger?


    • 3
      TypicalToxic  commented on Jan. 20, 2017, 7:17 p.m.

      String, byte array, int array, char array, etc


    • 4
      Kirito  commented on Jan. 19, 2017, 10:49 p.m.

      You could always look into how BigInteger works internally. Besides, allowing BigInteger would be unfair to languages that don't have it, and would also defeat the purpose of the question.


  • 0
    paydayzcool  commented on Oct. 19, 2016, 12:29 p.m.

    Just wondering, why is there no Python 3 in the allowed languages?


    • 1
      nathanl3  commented on Oct. 19, 2016, 12:45 p.m.

      Allowing Python would make the problem trivial because of Python's support of arbitrarily big numbers.


      • -1
        paydayzcool  commented on Oct. 20, 2016, 3:26 a.m.

        Oh, right.


  • -1
    TypicalToxic  commented on Sept. 13, 2016, 12:10 a.m.

    uh, java.lang.NumberFormatException?


    • -2
      Xyene  commented on Sept. 13, 2016, 12:11 a.m.

      Each positive integer has a maximum of 50 digits.

      (much larger than what can fit in even a long)


      • -2
        TypicalToxic  commented on Sept. 13, 2016, 12:14 a.m.

        0-50+ digits works on my computer? w/o errors?


        • 0
          Xyene  commented on Sept. 13, 2016, 12:22 a.m.

          My bad, I assumed that would be your issue without reading your code. Try a number like 848098180322800092606233221468227354577849547220.


          • -2
            omaewamoushindeiru  commented on Dec. 20, 2016, 5:17 p.m.

            Hm, all the big numbers work in my code but I keep getting that NumberFormatError, any tips?


            • -2
              TypicalToxic  commented on Dec. 21, 2016, 2:10 a.m.

              Try numbers:

              54862354760000000000532645 10000000000500000000007


          • -2
            TypicalToxic  commented on Sept. 13, 2016, 1:36 a.m.

            I did it bois. Thank you!


  • -6
    Kirito  commented on Sept. 5, 2016, 6:54 p.m.

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


  • 14
    nathanl3  commented on Sept. 2, 2016, 11:51 p.m.

    What's the exact text to output if the number is not divisible by 11? "The number ____ is not divisible by 11."?


    • -3
      Kirito  commented on Sept. 3, 2016, 12:11 a.m.

      Yes.