TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

ISBNumber

Problem statement, definition, constraints, and public examples.

Problem Statement

The last digit of the 10-digit International Standard Book Number (ISBN) is used to detect single-position errors and transposition errors. For example, ISBN of Ivor Horton's Beginning Java is 1-861000-27-8. The first digit indicates the country. The next block of digits -861000- identifies the publisher. The third block -27- is assigned by the publisher and identifies a particular book. The last digit is the check digit.

The last digit is calculated in such a way that the last digit plus 2 times the ninth digit, plus 3 times the eighth digit, plus 4 times the seventh digit and so on, ..., plus 9 times the second digit, plus 10 times the first digit is evenly divisible by 11. Sometimes, the formula gives 10 for the check digit. In this case, publishers use the character 'X' to represent the check digit 10.

Your task is, given the first 9 digits of ISBN, return the check digit.

Definition

Class:
ISBNumber
Method:
checkDigit
Parameters:
String
Returns:
char
Method signature:
char checkDigit(String num)
(be sure your method is public)

Constraints

  • num contains exactly 11 characters, 9 of them are digits [0-9] and the other two are dashes '-'
  • second character of num is a dash, another dash will occupy a place in num between the 4th and the 9th character inclusive

Examples

  1. "1-861000-27"
    Returns: '8'
    8 + 2*7 + 3*2 + 4*0 + 5*0 + 6*0 + 7*1 + 8*6 + 9*8 + 10*1 = 165, is divisible by 11. (Ivor Horton. Beginning Java).
  2. "0-07-882149"
    Returns: '5'
    (Harley Hahn. The Unix Companion).
  3. "0-471-11709"
    Returns: '9'
    (Bruce Schneier. Applied Cryptography).
  4. "0-425-09961"
    Returns: 'X'
    10 + 2*1 + 3*6 + 4*9 + 5*9 + 6*0 + 7*5 + 8*2 + 9*4 + 10*0 = 132, is divisible by 11. (Agatha Christie. Thirteen at Dinner).
Back to all problems