QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#363652 | #7698. ISBN Conversion | lucasrpatten# | WA | 8ms | 10028kb | Python3 | 1.4kb | 2024-03-24 01:32:11 | 2024-03-24 01:32:11 |
Judging History
answer
t = int(input())
for _ in range(t):
x = input()
if x.count("-")==3 and x[-2]!="-":
print('invalid')
continue
hyphen_before = True
hyphen_count = 0
total_numbers = 0
total_count = 0
checksum_len = 0
ib10_value = 0
broken=False
for v in x:
if total_numbers == 10:
broken=True
break
elif v == "-":
if hyphen_count == 3 or hyphen_before:
broken=True
break
hyphen_count+=1
hyphen_before = True
# checksum_len=0
elif v in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "X"]:
hyphen_before = False
if v == "X":
v = 10
v = int(v)
ib10_value += v*(10-total_numbers)
if total_numbers == 9:
total_numbers += 1
continue
if checksum_len % 2 == 0:
total_count += 3*v
else:
total_count += v
checksum_len+=1
total_numbers+=1
else:
broken=True
break
mod = (ib10_value)%11
if mod != 0:
broken = True
if broken:
print('invalid')
continue
total_count += 8
print(f"978-{x[:-1]}{10-total_count%10}")
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 9900kb
input:
4 3-540-4258-02 039428013X 3-540-42580-2 0-14-028333-3
output:
invalid 978-0394280134 978-3-540-42580-9 invalid
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 8ms
memory: 10028kb
input:
25 ---------- ----------- ------------ ------------- XXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXX XXXXXXXXXXXXX ---------X ----------X -----------X 01234567890 012345678901 0123456789012 -0123456789- 0123456789- -0123456789 01--23456789 012345678--9 0123456789-- --0123456789 98765432-1 987-654-321 87-645-32-...
output:
invalid invalid invalid invalid 978-XXXXXXXXX2 invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid 978-98765432-7 978-987-654-327 978-87-645-32-4 invalid
result:
wrong answer 5th lines differ - expected: 'invalid', found: '978-XXXXXXXXX2'