2009 Canadian Computing Competition, Stage 1

Problem J1: ISBN

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 add

9×1 + 7×3 + 8×1 + 0×3 + 9×1 + 2×3 + 1×1 + 4×3 + 1×1 + 8×3 + 9×1 + 4×3 + 8×1

to get 120.

The special property of an ISBN number 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.

Sample Input

9
4
8

Sample Output

The 1-3-sum is 120

Sample Input 2

0
5
2

Sample Output 2

The 1-3-sum is 108

All Submissions
Best Solutions


Point Value: 3
Time Limit: 2.00s
Memory Limit: 16M
Added: May 14, 2009

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

It says that the ISBN number is a multiple of 10. But in in sample output 2 it says that the sum is 108. the question is contradicting the answer. ???

The problem says that the input is a 13 digit sequence. It doesn't say that it's a valid ISBN.