QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#546525#7698. ISBN Conversiontruebqccq#WA 14ms10688kbPython31.3kb2024-09-04 08:23:352024-09-04 08:23:35

Judging History

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

  • [2024-09-04 08:23:35]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:10688kb
  • [2024-09-04 08:23:35]
  • 提交

answer

DIGIT = '0123456789'

def solve():
    code = input()
    total = 0
    idx = 0
    hyphens = []
    for i,x in enumerate(code):
        if x == '-':
            hyphens.append(i)
            continue
        if idx == 9:
            if x == 'X':
                total += 10
            else:
                total += int(x)
            idx += 1
            continue
        if x == 'X':
            print('invalid')
            return
        total += (10-idx)*int(x)
        idx += 1
    if idx != 10:
        print('invalid')
        return
    if total % 11 != 0:
        print('invalid')
        return
    if len(hyphens) > 0:
        if hyphens[0] == 0 or hyphens[-1] == len(code)-1:
            print('invalid')
            return
    if len(hyphens) == 3 and hyphens[2] != 11:
        print('invalid')
        return
    if len(hyphens) > 3:
        print('invalid')
        return
    for i in range(len(hyphens)-1):
        if hyphens[i]+1 == hyphens[i+1]:
            print('invalid')
            return
    
    code = '978-' + code[:-1]
    idx = 0
    total = 0
    for i,x in enumerate(code):
        if x == '-':
            continue
        total += (2*idx+1)*int(x)
        idx = 1-idx
    code += f'{10-total%10}'
    print(code)
    









t = int(input())
while t > 0:
    solve()
    t-=1

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 14ms
memory: 10596kb

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: 12ms
memory: 10684kb

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: 7ms
memory: 10688kb

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: 4ms
memory: 10624kb

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: 10ms
memory: 10684kb

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: 13ms
memory: 10616kb

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: 14ms
memory: 10684kb

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'