CCF-CSP certification exam ISBN number

Problem Description

Question number: 201312-2
Questions Name: ISBN number
time limit: 1.0s
Memory Limit: 256.0MB
Problem Description:
Problem Description
  Each official publication of this book has a corresponding ISBN number, ISBN code comprising a 9-digit number, an identification code and a separator 3, which is a predetermined format such as "x-xxx-xxxxx-x ", where the symbol " - "is a delimiter (minus sign on the keyboard), the last one is the identification code, e.g. ISBN 0-670-82162-4 is a standard code. The first digit represents the ISBN code of books published in five languages, such as 0 for English; first separator "-" represents the three digits after the press, such as 670 representatives of Viking Press; the second five digits after separation the book represents the number of the publishing house; the last one is the identification code.
  Identification code calculated as follows:
  the first number multiplied by 1 plus the second digit is multiplied by 2 ...... and so on, with the results obtained mod 11, resulting remainder is the identification code, if the remainder is 10, the identification code is capital letter X. E.g. ISBN 0-670-82162-4 number of the identification code is thus obtained 4: 067,082,162 of nine digits, from left to right, are multiplied by 1, 2, ..., 9, and then summed, i.e., 0 × 1 + 6 × 2 + ...... + 2 × 9 = 158, 158 mod 11 and then take the results of 4 as an identification code.
  Analyzing programming ISBN number inputted identification code is correct, if correct, then the output only "Right"; if an error, the output is correct ISBN number.
Input Format
  Enter only one line, it is a sequence of characters representing ISBN number of a book (to ensure input the required format ISBN numbers).
Output Format
  Output line, ISBN number if the identification code entered correctly, then the output "Right", otherwise, according to a predetermined format, output the correct ISBN number (including separators "-").
Sample input
0-670-82162-4
Sample Output
Right
Sample input
0-670-82162-0
Sample Output
0-670-82162-4

 

 

#include <bits / stdc ++. h> // almost universal header files

using namespace std;


int main()
{
char ISBN[14];
gets(ISBN);
int id = 0;
int mul = 1;
for(int i=0; i<11; i++){
if(ISBN[i]>='0' && ISBN[i]<='9'){
id+= (ISBN[i]-'0')*mul;
//cout<<"id:"<<id<<endl;
mul++;
}
}
//cout<<"mul:"<<mul<<endl;
id=id%11;
//cout<<"id:"<<id<<endl;
if(ISBN[12]==(id+'0')){
cout<<"Right";
}
else if(ISBN[12]=='X' && id==10){
cout<<"Right";
}
else{
if(id==10){
ISBN[12]='X';
}
else{
ISBN[12]=id+'0';
}
puts(ISBN);
}
return 0;
}

Come on! ! !

Guess you like

Origin www.cnblogs.com/yu-xia-zheng-ye/p/11311607.html