| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 (추가 시간 없음) | 1024 MB | 69 | 25 | 25 | 40.323% |
An ISBN (International Standard Book Number) is a unique identifier assigned to a distinct edition/version of a published book (for example, hardcover and paperback versions of the same edition get different ISBNs). ISBNs assigned before 2007 were 10ドル$ digits long (the ISBN-10 standard), and ISBNs assigned on or after January 1, 2007, are 13ドル$ digits long (the ISBN-13 standard). Some books issued before 2007 that are still in print have both an original ISBN-10 and a matching ISBN-13, and some newer books are also given both an ISBN-10 and an ISBN-13, the former for backward-compatibility purposes. That "double identity" situation is the basis for this problem, which requires you to convert valid ISBN-10s to their corresponding ISBN-13s.
The last digit of any ISBN is a checksum digit that can be used for simple error detection. ISBN-10 and ISBN-13 use different rules for computing/verifying this last digit:
It is not hard to see that each rule uniquely determines the checksum digit (given the other digits).
X Factor: Note the following small but important detail for ISBN-10 that does not apply to ISBN-13: because the modulus $\textrm{is }11,ドル the value of the checksum digit lies in $\{0, 1, 2, \ldots, 9, 10\},ドル and in the special case that the value of the checksum digit $\textrm{is }10,ドル it is written as X so that only one character is required. So, for example, 039428013ドル\textrm{X}$ is a valid ISBN-10.
Hyphens: Technically an ISBN-10 consists of four parts, one of which is the checksum digit. (The exact rules defining the first three parts are complicated, so we will not deal with them here.) Two adjacent parts can optionally be separated by a hyphen, which means that an ISBN-10 may contain up to three hyphens, but it cannot begin or end with a hyphen, and it cannot contain consecutive hyphens. If there are three hyphens, one must separate the checksum digit from the digit that precedes it (if there are fewer than three hyphens, there may or may not be a hyphen between the checksum digit and the digit that precedes it). So, for the purposes of this problem, the following are valid ISBN-10s:
039428013ドル\textrm{-X}$
0ドル\textrm{-}39\textrm{-}428013\textrm{X}$
3ドル\textrm{-}540\textrm{-}42580\textrm{-}2$
3540425802ドル$
And the following are invalid ISBN-10s (the first two because of a hyphen-placement error, the last because it fails the checksum test above):
3ドル\textrm{-}540\textrm{-}4258\textrm{-}02$
3ドル\textrm{-}540\textrm{-}425802\textrm{-}$
0ドル\textrm{-}14\textrm{-}028333\textrm{-}3$
How do you convert an ISBN-10 to an ISBN-13? Simply (i) prepend the three digits 978ドル,ドル (ii) remove the old checksum digit, and (iii) append a new checksum digit as determined by the ISBN-13 rule.1 To keep things simple, maintain the positions of any existing hyphens, and follow the prepended 978 with a hyphen.
1In general, an ISBN-13 can begin with three digits other than 978, but only 978 can be prepended to an ISBN-10 to form the matching ISBN-13.
The first line of input contains an integer, $T$ $(1 \leq T \leq 25),ドル the number of (possibly invalid) ISBN-10s to process. This is followed by $T$ lines, each of which contains a nonempty string of length between 10ドル$ and 13ドル,ドル inclusive. Each character is either a $\textrm{base-}10$ digit ('0' to '9'), a hyphen ('-'), or 'X' (capital X).
For each test case, if the candidate ISBN-10 is not valid according to the details given above, output a line containing "invalid". Otherwise, output a line containing the corresponding ISBN-13.
4 3-540-4258-02 039428013X 3-540-42580-2 0-14-028333-3
invalid 978-0394280134 978-3-540-42580-9 invalid
ICPC > Regionals > North America > East Central North America Regional > 2023-2024 East Central NA Regional Contest I번
ICPC > Regionals > North America > Greater New York Region > 2023 Greater New York Programming Contest I번