本题用C++写要用高精度,py直接模拟即可
py中的字符串反转可以用切片操作,对于字符串s,将它反转:s = s[::-1]
n,k = input().split()
k = int(k)
cnt = 0
reverse = n[::-1]
while reverse != n:
cnt += 1
Sum = int(n) + int(reverse)
n = str(Sum)
reverse = n[::-1]
if cnt == k:
break
print(n)
if cnt == k:
print(k)
else:
print(cnt)