hebedich 通过本文主要向大家介绍了go语言,go语言环境搭建,go语言程序设计,let it go 25种语言,go语言教程等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
hano.go
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
fmt.Print("输入要移动的盘子数:")
reader := bufio.NewReader(os.Stdin)
lool:
data, _, _ := reader.ReadLine()
n, err := strconv.Atoi(string(data))
if err != nil {
fmt.Println(err)
goto lool
}
hanoi(n, 'A', 'B', 'C')
}
func hanoi(n int, a, b, c byte) {
if n > 1 {
hanoi(n-1, a, c, b)
fmt.Printf("%c-->%c\n", a, c)
hanoi(n-1, b, a, c)
} else {
fmt.Printf("%c-->%c\n", a, c)
}
}
</div>
以上所述就是本文的全部内容了,希望大家能够喜欢。
</div>
