汉诺塔

n = int(input())
count = 0
def han(n,a,b,c):
global count
if n == 1:
print("将第{}个从{}搬到{}".format(1,a,c))
count += 1
else:
hanoi(n-1,a,c,b)
print("将第{}个从{}搬到{}".format(n,a,c))
count += 1
han(n-1,b,a,c)
han(n,'A','B','C')
print("共{}步".format(count))

posted @ 2020-03-31 19:54  Xiao_kong  阅读(124)  评论(0编辑  收藏  举报