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 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 10-670-82162-4 sample output 1Right sample input 20-670-82162-0 sample Output 20-670-82162-4
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;intMain () {Charisbn[ -]; intnum[Ten]; intsum; Charch; while(~SCANF ("%s", ISBN)) {Sum=0; num[0]=isbn[0]-'0'; num[1]=isbn[2]-'0'; num[2]=isbn[3]-'0'; num[3]=isbn[4]-'0'; num[4]=isbn[6]-'0'; num[5]=isbn[7]-'0'; num[6]=isbn[8]-'0'; num[7]=isbn[9]-'0'; num[8]=isbn[Ten]-'0'; num[9]=isbn[ A]-'0'; for(intI=0, j=1;i<9; i++,j++) {sum+=num[i]*J; } Sum%= One; if(sum<Ten) Ch=sum+'0'; ElseCH='X'; if(ch==isbn[ A]) puts (" Right"); Else{isbn[ A]=ch; Puts (ISBN); } } return 0;}
ISBN number-CCF simulation question