CCC '96 S2 - Divisibility by 11

View as PDF

Submit solution


Points: 7
Time limit: 2.0s
Memory limit: 16M

Problem type

Allowed languages
Assembly , C , C++ , COBOL , Fortran , Java , Pascal , Prolog , Text

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

1
12345678901234567900

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.

Comments


  • 0
    Inyj  commented on June 29, 2018, 12:40 p.m. edit 5

    Someone please add a multiple input output format


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

    DAMN

    I forgot "."

    ......


  • 4
    trollakatroll  commented on Jan. 21, 2017, 10:59 a.m.
    I DID IT FINALLY!!!

    i have to say i have some concerns about your requirements and because of that it has caused me to fail many times. you should explain just a bit more and it would be a lot clearer.


  • 2
    trollakatroll  commented on Jan. 19, 2017, 5:19 p.m.
    WHAT DO YOU USE TO HOLD THIS BIG NUMBER?

    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?


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

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


    • 2
      Kirito  commented on Jan. 19, 2017, 5: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.


      • 1
        trollakatroll  commented on Jan. 20, 2017, 9:52 a.m.

        thanks alot :)


  • 1
    paydayzcool  commented on Oct. 19, 2016, 8:29 a.m.
    Why is there no Python 3 in the allowed languages?

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


    • 1
      nathanl3  commented on Oct. 19, 2016, 8:45 a.m.

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


      • 0
        paydayzcool  commented on Oct. 19, 2016, 11:26 p.m.

        Oh, right.


  • -1
    TypicalToxic  commented on Sept. 12, 2016, 8:10 p.m.
    SOS?

    uh, java.lang.NumberFormatException?


    • 1
      Xyene  commented on Sept. 12, 2016, 8:11 p.m.

      Each positive integer has a maximum of 50 digits.

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


      • 0
        TypicalToxic  commented on Sept. 12, 2016, 8:14 p.m.

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


        • 1
          Xyene  commented on Sept. 12, 2016, 8:22 p.m.

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


          • 0
            BMP  commented on Dec. 20, 2016, 12:17 p.m.

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


            • 0
              TypicalToxic  commented on Dec. 20, 2016, 9:10 p.m.

              Try numbers:

              54862354760000000000532645 10000000000500000000007


          • 0
            TypicalToxic  commented on Sept. 12, 2016, 9:36 p.m.

            I did it bois. Thank you!


  • 0
    Kirito  commented on Sept. 5, 2016, 2:54 p.m.
    New Testcases

    New testcases were added, and all submissions have been rejudged.


  • 5
    nathanl3  commented on Sept. 2, 2016, 7:51 p.m.
    What to output if not divisible?

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


    • 0
      Kirito  commented on Sept. 2, 2016, 8:11 p.m.

      Yes.