想试试另一种方法来着,结果四个RE紫牌警告。。。
py大佬救救萌新吧~~
a = int(input())
c = a
b = [i for i in input()]
for i in range(30):
if b == b[::-1]:
exit(print(f"STEP={i}"))
f = 0
d = []
for j in range(len(b)):
if i != 0:
c = 10
e = int(b[j], base=c) +\
int(b[::-1][j], base=c)+f
f = 0
if e >= a:
f += 1
d.append(str(e - a))
else:
d.append(str(e))
if f != 0:
d.append(str(f))
b = d[::-1]
print("Impossible!")
真*手动测试了,没毛病呐
这种方法和我最开始的方法结果一毛一样的说
def ss(x, y): d = "" while True: z = x // y v = x % y d += f"{v if v < 10 else chr(v - 10 + ord('a'))}" if z < y: d += f"{z if z < 10 else chr(z - 10 + ord('a'))}" break x //= y return d[::-1] a = int(input()) b = input() for i in range(30): if b == b[::-1]: exit(print(f"STEP={i}")) b = ss(int(b, base=a) + int(b[::-1], base=a), a) print("Impossible!")
是不是我该换个编译器了。。。