CCC '09 J1 - ISBN

View as PDF

Submit solution

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

Problem type
Canadian Computing Competition: 2009 Stage 1, Junior #1

The International Standard Book Number (ISBN) is a 13-digit code for identifying books. These numbers have a special property for detecting whether the number was written correctly.

The 1-3-sum of a 13-digit number is calculated by multiplying the digits alternately by 1's and 3's (see example) and then adding the results. For example, to compute the 1-3-sum of the number 9780921418948 we perform:

\displaystyle 9 \times 1 + 7 \times 3 + 8 \times 1 + 0 \times 3 + 9 \times 1 +
2 \times 3 + 1 \times 1 + 4 \times 3 + 1 \times 1 + 8 \times 3 +
9 \times 1 + 4 \times 3 + 8 \times 1 = 120

The special property of an ISBN is that its 1-3-sum is always a multiple of 10.

Write a program to compute the 1-3-sum of a 13-digit number. To reduce the amount of typing, you may assume that the first ten digits will always be 9780921418, like the example above. Your program should input the last three digits and then print its 1-3-sum. Use a format similar to the samples below.

Sample Input 1

9
4
8

Sample Output 1

The 1-3-sum is 120

Sample Input 2

0
5
2

Sample Output 2

The 1-3-sum is 108

Comments


  • -1
    nir1  commented on June 25, 2022, 4:25 p.m.

    My PY3 code gives me a type error but in another tab it gives the proper output. I'm not sure what the problem is.


  • -1
    Tempest_Enderman  commented on March 17, 2021, 8:51 a.m. edited

    Can anyone tell me how to calculate the ISBN number? 0 times 3 + 5 + 2 times 3 is obviously not 108!


    • 6
      Badmode  commented on March 17, 2021, 2:30 p.m.

      To reduce the amount of typing, you may assume that the first ten digits will always be 9780921418


  • -20
    Marshmellon  commented on March 9, 2021, 1:51 p.m.

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


  • 11
    350023289  commented on Feb. 21, 2020, 2:03 a.m.

    You have to write the full sentence


  • 7
    CoolNoobyBooby  commented on Aug. 26, 2018, 12:14 a.m.

    Oh. I forgot the sentence.


  • 17
    quantum  commented on Sept. 26, 2014, 1:43 a.m.

    Note that your output must exactly be the same as specified.

    The 1-3-sum is 120 is fine, but 120 is wrong, and The 1-3-sum is 120. (notice the period) is also wrong.


    • 6
      jfu0952  commented on Aug. 1, 2018, 2:50 a.m. edit 2

      Agreed! (Also remember that BRACKETS MATTER)!