CCF Simulation question 2-ISBN number

Source: Internet
Author: User

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 separator (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
Enter only one line, which is a sequence of characters that represents the ISBN number of a book (guaranteed to enter the format required for the ISBN number).
output Format
Output a 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 1
0-670-82162-4
Sample Output 1
Right
Sample Input 2
0-670-82162-0
Sample Output 2
0-670-82162-4
1#include <iostream>2 3 using namespacestd;4 5 intMain () {6     strings;7     inta[Ten];8Cin>>s;9a[0] = s[0]-'0';Tena[1] = s[2]-'0'; Onea[2] = s[3]-'0'; Aa[3] = s[4]-'0'; -a[4] = s[6]-'0'; -a[5] = s[7]-'0'; thea[6] = s[8]-'0'; -a[7] = s[9]-'0'; -a[8] = s[Ten]-'0'; -a[9] = s[ A]-'0'; +     intsum =0; -      for(intI=0, j=1;i<9; i++,j++) +     { Asum+=a[i]*J; at     } -     intCode = sum% One; -     Charc = code==Ten?'X':(Char)('0'+code); -     if(Code = = a[9]) -     { -cout<<" Right"<<Endl; in     } -     Else to     { +s[ A] =C; -cout<<s<<Endl; the     } *     return 0; $}

CCF Simulation question 2-ISBN number

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.