| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12486 | Tower of Hanoi |
|
| 12487 | Dictionary Order |
|
Description
The Tower of Hanoi is a mathematical game puzzle. It consists of three rods, which are A, B and C. The puzzle starts with n disks in ascending order of size on rod A, the smallest at the top.
The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. 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.
3. No disk may be placed on top of a smaller disk.
Write a program to simulate the optimal moves of the disks. Print the number of disk which is moved in each step.
For example, if n = 3, the moves of each steps are:
move disk 1 from rod A to rod C
move disk 2 from rod A to rod B
move disk 1 from rod C to rod B
move disk 3 from rod A to rod C
move disk 1 from rod B to rod A
move disk 2 from rod B to rod C
move disk 1 from rod A to rod C

HINT : You can modify this sample code and implement the function 'hanoi'
#include <stdio.h>
void hanoi(int n, char A, char B, char C);
int main(){
int n;
scanf("%d", &n);
hanoi(n, 'A', 'B', 'C');
return 0;
}
Input
An integer n (0<n<20), which means the number of disk.
Output
Print out the information of each step, and there is a '\n' at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
A permutation, also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list into a one-to-one correspondence sequence.
ORDER is important !! You should display it in dictionary order.(also known as lexical order, alphabetical order or lexicographic(al) product)
Please solve it by "recursion" or "loop".
No point if you use C++ STL !!!!
ex. N=c,
a b c
a c b
b a c
b c a
c a b
c b a
Input
N
N is a alpahbet. N could be a,b,c,d,e,f.
Output
S_1
S_2
.
.
.
S_?
You need to change line even in the last line.