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

PROGRAMMING:The old tower of Hanoi

Luz5年前 (2021-05-10)题库424
There are three pillars a, B and C, $$n $$disks with different diameters. These disks are placed on pillar a from bottom to top according to the order of diameter from large to small. If a disk is moved from one pillar to another, it is called a move. In the process of moving, pillar B is allowed to be used, but the large disk is not allowed to be placed on the small disk. Now we need to use the least number of steps to move all these disks to the C-pillar. Please design an algorithm to find out the moving steps and times.
![ hanoi.png](~/3ddd9946-fa1a-4208-93ae-a1f9d94f66e9.png)
###Input format:
An integer $$n (1 / Leq n / Leq 15) $$, which represents the number of disks.
###Output format:
Output the process of moving the plate and the total number of times of moving. First output the moving steps, each step occupies one line. The format is: column number of the plate to be moved --- column number of the plate to be moved. The last line is the total number of moves.
###Input example:
```in
two
```
###Output example:
```out
A-->B
A-->C
B-->C
three
```







answer:If there is no answer, please comment