-->
当前位置:首页 > 题库

PROGRAMMING:The tower of Hanoi problem

Luz5年前 (2021-05-10)题库436
Hanoi tower is a puzzle toy originated from ancient Indian legend. It is said that when Brahma created the world, he made three diamond pillars. On one pillar, 64 pieces of gold discs were stacked according to the size order from bottom to top. Brahma ordered the monks to move the disc to another pillar, and stipulated that the disc could not be enlarged on a small disc, only one disc could be moved at a time. When all the disks move to another pillar, the world will be destroyed.
![ Title 1. JPG] (~ / eac25442-22c9-4b87-8cf8-e8a69ea0cf02. JPG)
Please write a program, input the number of Hanoi Tower disc, output the steps of moving Hanoi tower.
####Input format
>Number of disks
>Initial column and transition column
####Output format
>Steps to move the tower of Hanoi
>Each line displays one step of operation. The specific format is as follows:
>Disc number: start column → destination column
>The disc number is numbered from 1 to 1.
####Input sample
```in
three
a c b
```
####Output sample
```out
1: a -> c
2: a -> b
1: c -> b
3: a -> c
1: b -> a
2: b -> c
1: a -> c
```







answer:If there is no answer, please comment