If you are in the HKOI enrichment class, you have not learned string processing yet. Here is how to read a single digit from input in C++:
- Create an integer variable
int x;
- Read one integer digit into the variable:
scanf("%1d", &x);
Do this repeatedly to read every digit in the input.
Make sure to include the library <iostream>
.
If you are using this approach, do not use cin
in your code.
Reading from two different stdin
streams can be problematic.
The International Standard Book Number (ISBN) serve as a (mostly) unique identifier for books sold across the globe. The 10-digit ISBN format was published by the International Organization for Standardization (ISO) in 1970. Since then it had been used until 2007 when it got replaced by a 13-digit format.
For now, we focus on the 10-digit format called ISBN-10. ISBN-10 comes with a check digit: it is the 10th and last digit of the ISBN. The ISBN-10 is designed so that the alteration of a single digit and transposition of adjacent digits can be detected using the check digit.
Let's label the digits of an ISBN-10 as $x_1, \cdots, x_{10}$. A valid ISBN-10 is required to satisfy a mathematical property: the sum
$$1 \cdot x_1 + 2 \cdot x_2 + \cdots + 9 \cdot x_9 + 10 \cdot x_{10}$$must be divisible by 11.
So, the check digit $x_{10}$ is allowed to range from 0 to 10.
In the case that $x_{10} = 10$, the symbol X
is used as the digit instead.
Given the first 9 digits of an ISBN-10, append the check digit that turns it into a valid ISBN-10.
Input
The only line of input contains the first 9 digits of an ISBN-10.
Output
Output the full ISBN-10, including the check digit, which is either 0-9 or the character X
.
Sample Test Cases
Input | Output | |
---|---|---|
109299621 | 1092996214 | |
052557655 | 052557655X |
Scoring: Per Subtask
Authored by s16f22
Appeared in 2024 Mini Contest 0