|
Time |
Memory |
| Case 1 |
1 sec |
32 MB |
| Case 2 |
1 sec |
32 MB |
| Case 3 |
1 sec |
32 MB |
| Case 4 |
1 sec |
32 MB |
| Case 5 |
1 sec |
32 MB |
Description
Tower of Hanoi is a mathematical puzzle where we have three rods and N disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:

- Only one disk can be moved at a time.
- Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
- No disk may be placed on top of a smaller disk.
Given a integer N to represents N disks. Please write a C program to show all the steps to move all N disks from rod 'A' to rod 'C'.
Input
An integer N to represent the number of disks.
Note that:
- 1 <= N <= 16
Output
Output should follow below format:
Disk n moved from X to Y
…
Note that:
- Need to have a return value('\n') at the end of your string.
- n is the number of moving disk.
- X, Y are one of ‘A’, ‘B’, ‘C’, which represents the index of rod. ‘A’ is the first rod, ‘B’ is the second rod, and ‘C’ is the third rod.
Tags