QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#363795#7698. ISBN Conversionlucasrpatten#WA 11ms10048kbPython3900b2024-03-24 03:29:012024-03-24 03:29:02

Judging History

你现在查看的是最新测评结果

  • [2024-03-24 03:29:02]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:10048kb
  • [2024-03-24 03:29:01]
  • 提交

answer

d = {str(i):i for i in range(10)}
d['X'] = 10
n=int(input())

def checksum(isbn):
    p = False
    s = 0
    for i in range(len(isbn)):
        if isbn[i] == '-':
            continue
        if p:
            s += d[isbn[i]] * 3
        else:
            s += d[isbn[i]]
        p = not p
    return isbn + str(10-s%10)




def check(isbn):
    hc = isbn.count('-')
    if len(isbn) - hc != 10 or '--' in isbn or isbn[0] == '-' or isbn[-1] == '-':
        return False
    if hc == 3 and isbn[-2] != '-':
        return False
    nums = ''.join(isbn.split('-'))
    if 'X' in nums and nums.index('X') != 9:
        return False
    s = 0
    for i in range(10):
        s += d[nums[i]] * (10-i)
    if s%11 != 0:
        return False
    return checksum('978-'+isbn[:-1])


for _ in range(n):
    isbn = input()
    o = check(isbn)
    if not o:
        print("invalid")
    else:
        print(o)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 9980kb

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: 0
Accepted
time: 11ms
memory: 9908kb

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
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid

result:

ok 25 lines

Test #3:

score: 0
Accepted
time: 5ms
memory: 9908kb

input:

5
71234567X1
71234567X-1
2-2345678-9
8X-7X-123456
7123X8123X

output:

invalid
invalid
invalid
invalid
invalid

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 5ms
memory: 10048kb

input:

10
3-540-42580-X
3-540-42580-3
0393609394
0-19-853453-9
0070131510
0070131512
0070131514
0070131516
0070131518
007013151X

output:

invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid

result:

ok 10 lines

Test #5:

score: 0
Accepted
time: 3ms
memory: 9916kb

input:

11
767-13423100
65955-01-15-1
778592-4222
3283-138-073
8-802896-37-4
514-2481525
356-52708-6-6
4-810-73599-7
3-28438-244-8
1-98-2031209
82-54-55344X

output:

invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid

result:

ok 11 lines

Test #6:

score: 0
Accepted
time: 10ms
memory: 9860kb

input:

12
0123456789
0-19-853453-1
0070131511
0-07-0131511
039428013-X
0-39-428013X
0-3942801-3X
0131103628
3-540-42580-2
3540425802
1535956828
1535-9-5682-8

output:

978-0123456786
978-0-19-853453-2
978-0070131514
978-0-07-0131514
978-039428013-4
978-0-39-4280134
978-0-3942801-34
978-0131103627
978-3-540-42580-9
978-3540425809
978-1535956826
978-1535-9-5682-6

result:

ok 12 lines

Test #7:

score: -100
Wrong Answer
time: 10ms
memory: 9976kb

input:

10
69289-01810
07-8-2406750
4946302-980
91-45-00652-0
2526831830
8370591930
022-18967-4-0
86340-22-25-0
862-57-6642-0
1691783730

output:

978-69289-018110
978-07-8-2406757
978-4946302-985
978-91-45-00652-8
978-2526831832
978-8370591939
978-022-18967-4-3
978-86340-22-25-4
978-862-57-6642-6
978-1691783731

result:

wrong answer 1st lines differ - expected: '978-69289-01810', found: '978-69289-018110'