本地运行样例测试点一第一个数据都对, 但提交全WA

P1015 [NOIP1999 普及组] 回文数

pCandka @ 2023-10-25 00:21:13

bit = tuple("0123456789ABCDEF")

def xToTen(num : str, base : int) -> int:
    result = int(0)
    l = int(len(num))
    for i in range(0, l):
        try:
            chN = int(num[l - i - 1])
        except ValueError:
            chN = ord(num[l - i - 1]) - ord('A') + 10
        result += chN * pow(base, i)
    return result

def tenToX(num : int, base : int) -> str:
    result = str()
    while num > 0:
        result += bit[num % base]
        num = int(num / base)
    return result[::-1]

if __name__ == "__main__":
    n = int(input())
    m = str(input())
    for i in range(1, 31):
        m = tenToX( xToTen(m, n) + xToTen(m[::-1], n),n)
        if m == m[::-1]:
            print("STEP=%d" % (i))
            exit()
    print("Impossible!")

|