Go语言实现汉诺塔算法
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) } }
以上所述就是本文的全部内容了,希望大家能够喜欢。
相关推荐
蜗牛慢爬的李成广 2020-04-07
ericxieforever 2020-03-28
shawsun 2020-03-01
蜗牛慢爬的李成广 2019-12-08
HLW0 2012-02-01
sxyyu 2019-07-01
LITElric 2019-07-01
wangxiaohua 2010-05-30
wuxiaosi0 2019-03-13
cyjsky 2017-05-20
MrA 2018-07-05
jiayuqicz 2018-04-18
yancey木易的blog 2018-03-19
tiewen 2019-02-18
BlowfishKing 2015-04-21
HTML学堂码匠 2016-05-17
danwenxuan 2014-07-23
jiayuqicz 2018-09-27
不羈 2008-05-02