29: ISBN number, 29isbn number

Source: Internet
Author: User
Tags uppercase letter

29: ISBN number, 29isbn number
29: ISBN number

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

Each officially published book corresponds to an ISBN number. The ISBN code consists of nine digits, one-digit identification code, and three separators, the format is as follows: "x-xxx-xxxxx-x", where the symbol "-" is a separator (minus sign on the keyboard), and the last digit is an identifier, 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 represents English, and three digits after the first separator "-" represent the publishing house, for example, 670 represents the Viking Publishing House; the fifth digit after the second separator represents the number of the book in the press; the last digit is the identification code.

The identifier calculation method is as follows:

Multiply the first digit by 1 and the second digit by 2 ...... Similarly, if mod 11 is used, the remainder is the identification code. If the remainder is 10, the identification code is an uppercase letter X. For example, Id 4 of ISBN numbers 0-670-82162-4 is obtained as follows: for the 9 Numbers 067082162, multiply them from left to right by 1, 2 ,..., 9, then sum, that is, 0 × 1 + 6 × 2 + „ + 2 × 9 = 158, and then take Result 4 of 158 mod 11 as the identification code.

Your task is to write a program to determine whether the identifier in the input ISBN number is correct. If it is correct, only "Right" is output. If it is incorrect, the ISBN number that you think is correct is output.

Input
Only one line is a character sequence, indicating the ISBN number of a book (ensure that the input meets the ISBN number format requirements ).
Output
If the ID of the ISBN number is correct, "Right" is output. Otherwise, the correct ISBN number (including the separator "-") is output according to the specified format.
Sample Input
Example #1:0-670-82162-4 example #-670-82162-0
Sample output
Example #1: Right example #-670-82162-4
Source
No. 1 in NOIP2008 semi-finals popularity Group
 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int t=0,sum=0; 6 char n[15]; 7 scanf("%s",n); 8 int len=strlen(n); 9 for(int i=0;i<len-1;++i)10 {11 if(n[i]>='0'&&n[i]<='9')sum+=(++t)*(n[i]-'0');12 }13 if(sum%11==n[len-1]-'0'||sum%11==10&&n[len-1]=='X')printf("Right");14 else{15 n[len-1]='\0';16 printf("%s",n);17 if(sum%11!=10)printf("%d",sum%11);18 else printf("X");19 }20 return 0;21 }

 

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.