1996 Canadian Computing Competition, Stage 1

Problem B: Divisibility by 11

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).

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.
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


Sample Output

The number 12345678901234567900 is divisible by 11.

All Submissions
Best Solutions

Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 28, 2008

Problem Types: [Show]

Languages Allowed:
C++03, PAS, C, ASM, C#, C++11

Comments (Search)

I would be very grateful if someone can tell me what is wrong with my code. I works perfectly on the sample test case. I am new to c++ so I am not sure if I am doing something wrong.

You're using unsigned long longs, which hold up to 2^64 - 1, or about 21 digits.

However, the input may contain up to 50 digits. There is no built-in integer type capable of handling numbers of that size.

whats wrong with my code?

It's simply wrong.

If you'd like more specific help, consider making your indentation consistent so others can read it.

Why does this not take java programs?

why does it not take python code?

because it's too easy in python

Usually in these questions there's something that says what you should output if the test case isn't true, or in this case, divisible by 11. For this question, what do you output if it isn't divisible by 11?

The number 12345678901234567901 is not divisible by 11.

"As long as the number being tested has more than two digits, form a new number by..."

I don't think the number has to be more than 2 digits, because 22, 33, etc. are all divisible by 11. Am I right?

once you get to a number that's two digits long, then you check toe see whether or not it's divisble by 11.