The ISBN number of the CCF series (201312-2)

Source: Internet
Author: User

Question name: ISBN number

Time limit: 1.0s

Memory Limit: 256.0MB

Problem Description:

Problem description Each published book has an ISBN number corresponding to it, the ISBN code includes 9-digit, 1-bit identification number and 3-bit delimiter, the specified format such as "X-xxx-xxxxx-x", where the symbol "-" is a delimiter (the keyboard minus), the last one is the identification code, For example, 0-670-82162-4 is a standard ISBN code. The first digit of the ISBN code represents the publishing language of the book, for example 0 for English; the three digits after the first delimiter "-" represent the publishing house, for example 670 for the Viking publishing house; the second separated five digits represent the number of the book in the publishing house; the last one is the identification code.
The identification code is calculated as follows:
Multiply the first number by 1 plus the second digit by 2 ... And so on, with the resulting mod 11, the remainder is the identification code, if the remainder is 10, then the identification code is an uppercase X. For example, the ISBN number 0-670-82162-4 in the identification code 4 is obtained: 067082162 of the 9 numbers, from left to right, respectively multiplied by 1,2,...,9, and then summed, that is, 0x1+6x2+......+2x9=158, and then take 158 mod 11 results of 4 as identification code.
Write the program to determine whether the identification code in the input ISBN is correct, if correct, only the "right", if the error, the output is the correct ISBN number. Input format input only one line, is a sequence of characters, representing the ISBN number of a book (guaranteed to enter the format required for the ISBN number). Output format output line, if the input ISBN number is correct, then output "right", otherwise, in accordance with the specified format, output the correct ISBN number (including the delimiter "-"). Sample input 0-670-82162-4 sample Output Right example input 0-670-82162-0 sample Output 0-670-82162-4

Problem Solving Ideas:

The code is as follows (Java):

      

1  PackageCcf_text2013_12;2 3 ImportJava.io.BufferedReader;4 ImportJava.io.InputStreamReader;5 /**6 * Each published book has an ISBN number corresponding to it, the ISBN code includes 9-digit, 1-digit identification number and 3-bit delimiter, the specified format such as "X-xxx-xxxxx-x",7 * Where the symbol "-" is a delimiter (a minus sign on the keyboard),8 * The last one is the identification code,9 * For example, 0-670-82162-4 is a standard ISBN code. Ten  *  One * The first digit of the ISBN code indicates the published language of the book, e.g. 0 for English; A * The three digits after the first delimiter "-" represent the publishing house, - * For example 670 represents the Viking publishing house; the second separated five digits represent the number of the book in the publishing house; the last one is the identification code.  -  *  the * The calculation method of the identification code is as follows: - * The first number multiplied by 1 plus the second digit multiplied by 2 ... And so on, using the resulting mod 11, the remainder is the identification code, - * If the remainder is 10, the identification code is an uppercase X.  -  *  + * For example, the ISBN number 0-670-82162-4 in the identification code 4 is obtained: - * For 067082162 of these 9 numbers, from left to right, multiply by 1,2,...,9, then sum, i.e. 0x1+6x2+......+2x9=158, + * then take 158 mod 11 result 4 as the identification code.  A  *  at * Write the program to determine whether the identification code in the input ISBN is correct, if correct, only the "right", if the error, the output is the correct ISBN number.  -  * @authorHello Stranger -  * -  */ -  Public classISBN { -  in      Public Static voidMain (string[] args) { -          toBufferedReader bin =NewBufferedReader (NewInputStreamReader (system.in)); +          -         Try{ the              *             intsum = 0; $             Panax Notoginseng             CharCC = ' 0 '; -              theString isbn_0 =bin.readline (); +              AString ISBN = isbn_0.replace ("-", "" "); the              +              for(inti = 0; I < 9; i++){ -                  $                 intII = (int) Isbn.charat (i)-48; $                  -sum + = II * (i + 1); -             } the              -sum = sum% 11;Wuyi              the             if(Sum = = 10){ -                  WuCC = ' X '; -                  About}Else{ $                  -CC = (Char) (Sum + 48); -                  -             } A              +             if(CC = = Isbn.charat (9)){ the                  -System.out.println ("Right"); $                  the}Else{ the                  theIsbn_0 = isbn_0.substring (0, 12) +cc; the                  - System.out.println (ISBN_0); in             } the              the}Catch(Exception e) { About              the e.printstacktrace (); the         } the     } +  -}

The ISBN number of the CCF series (201312-2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.