#coding=utf8 """题目内容: 如在汉诺塔游戏中,我们希望将塔A上的n个盘子,通过塔B移动到塔C,则对于任意输入的n,给出移动的步骤。 输入格式: 一个正整数n 输出格式: 移动的步骤 输入样例: 2 输出样例: Move 1 from A to B Move 2 from A to C Move 1 from B to C""" def hano(n,a,b,c): if n==1: print('Move %d from %s to %s'%(n,a,c)) return hano(n-1,'a','c','b') print('Move %d from %s to %s' % (n, a, c)) hano(n-1,'b','a','c') n=int(raw_input()) hano(n,'a','b','c')
python:汉诺塔
最新推荐文章于 2023-08-03 11:22:29 发布