#K57157. ISBN-13 Validator
ISBN-13 Validator
ISBN-13 Validator
You are given one or more ISBN-13 codes. An ISBN-13 code is considered valid if the weighted sum of its digits is a multiple of 10. Specifically, for an ISBN consisting of 13 digits \(d_1, d_2, \ldots, d_{13}\), the calculation is as follows:
\[ S = d_1 + 3\,d_2 + d_3 + 3\,d_4 + \cdots + d_{13} \]
If \(S \mod 10 = 0\), then the ISBN is valid; otherwise, it is invalid.
Your task is to process multiple ISBN-13 numbers provided via standard input and determine whether each is valid or invalid. For each ISBN, output "valid" if it is a valid ISBN-13, or "invalid" otherwise.
Example:
- Input: 9780470059029
- Output: valid
inputFormat
The input begins with an integer \(n\) on the first line indicating the number of ISBN codes. This is followed by \(n\) lines, each containing a 13-digit string representing an ISBN-13 number.
For example:
3 9780470059029 9781593275846 1234567890123
outputFormat
Output \(n\) lines. Each line should contain the word "valid" if the corresponding ISBN is valid according to the criteria, or "invalid" if it is not.
For the example input above, the output should be:
valid valid invalid## sample
3
9780470059029
9781593275846
1234567890123
valid
valid
invalid
</p>