You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
340 B

3 years ago
package main
3 years ago
import (
"fmt"
)
3 years ago
/***
问题 n 格元素从 A 经过 B 移动到 C
小数 必须在 大数的上侧及存在顺序问题
*/
func main() {
run(3, "A", "B", "C")
}
func run(n int, a, b, c string) {
if n > 0 {
run(n-1, a, c, b)
fmt.Println("从【" + a + "】移动到【" + c + "】")
run(n-1, b, a, c)
}
}