Python求助
查看原帖
Python求助
1037637
Akabane_Karuma楼主2023/9/19 21:01

作为某Py社长我居然卡在这一题

四个测试点在Pycharm上都运行正确,但是放到洛谷上变成#1 WA,#234 RE。。。

以下是拙劣的代码:

# 75分,RE
# 当前代码0分,WA+RE
def ords(s):
    if 48 <= ord(s) <= 57:
        return int(s)
    else:
        return ord(s)-55


def chrs(x):
    if 0 <= x <= 9:
        return str(x)
    else:
        return chr(x+55)


n = int(input())
m = input()
ans = 0
possible = False
for i in range(30):
    length = len(m)
    ans += 1
    addition1 = list(m)
    addition2 = list(m)
    addition2.reverse()
    sums = []
    for j in range(length+1):
        sums.append(0)
    for j in range(length):
        item = length-j
        sums[item] += (ords(addition1[item-1])+ords(addition2[item-1]))
        if sums[item] >= n:
            sums[item] -= n
            sums[item-1] += 1
    for j in range(length+1):
        sums[j] = chrs(sums[j])
    a = list(sums)
    b = sums
    b.reverse()
    addition = ''
    if a[0] == '0':
        del a[0]
        del b[length]
        length -= 1
    for j in range(length+1):
        addition += a[j]
    a = addition
    addition = ''
    for j in range(length+1):
        addition += b[j]
    b = addition
    if a == b:
        possible = True
        break
    m = a
if possible:
    print('STEP=%d' % ans)
else:
    print('Impossible!')

Python用习惯了所以不太会写高精,多多见谅哈

2023/9/19 21:01
加载中...