package main
import (
"fmt"
)
func hannuota(n int,A,B,C string){
if n<1 || n>20 {
return
}
if n==1{
fmt.Printf("盘子%d从%s柱子移动到%s柱子\n",n,A,C)
}else {
hannuota(n-1,A,C,B)
fmt.Printf("盘子%d从%s柱子移动到%s柱子\n",n,A,C)
hannuota(n-1,B,A,C)
}
}
func main() {
a,b,c:="A","B","C"
var val int
fmt.Println("请输入要移动的盘子数(1-20之间):N=")
fmt.Scanf("%d",&val)
hannuota(val,a,b,c)
}
汉诺塔go语言实现
最新推荐文章于 2024-04-17 11:14:45 发布