#P1055. [NOIP 2008 普及组] ISBN 号码

[NOIP 2008 普及组] ISBN 号码

Description

Every formally published book has an ISBN number associated with it. An ISBN consists of 99 digits, 11 check digit, and 33 separators. Its prescribed format is x-xxx-xxxxx-x, where the symbol - is the separator (the minus sign on the keyboard), and the last character is the check digit. For example, 0-670-82162-4 is a standard ISBN. The first digit indicates the publication language of the book (for example, 00 represents English); the three digits after the first separator - indicate the publisher (for example, 670670 represents Viking Press); the five digits after the second separator indicate the book’s identifier at that publisher; the last character is the check digit.

The check digit is computed as follows:

Multiply the first digit by 11, add the second digit multiplied by 22, and so on. Take the resulting sum mod11\bmod 11; the remainder is the check digit. If the remainder is 1010, then the check digit is the uppercase letter XX. For example, in the ISBN 0-670-82162-4, the check digit 44 is obtained as follows: take the nine digits 067082162 from left to right, multiply them by 1,2,,91,2,\dots,9 respectively and sum, i.e., 0×1+6×2++2×9=1580\times 1 + 6\times 2 + \cdots + 2\times 9 = 158, then take 158mod11158 \bmod 11, whose result 44 is the check digit.

Your task is to write a program to determine whether the check digit in the input ISBN number is correct. If it is correct, output Right only; if it is incorrect, output the ISBN number you believe to be correct.

Input Format

A character sequence representing a book’s ISBN number (the input is guaranteed to conform to the format requirements of ISBN numbers).

Output Format

One line. If the check digit of the input ISBN number is correct, output Right; otherwise, output the correct ISBN number in the prescribed format (including the separator -).

0-670-82162-4
Right
0-670-82162-0
0-670-82162-4

Hint

2008 Junior Problem 1.

Translated by ChatGPT 5