868 - I2P(I)2015_Chen_LAB_7 Scoreboard

Time

2015/11/19 13:25:00 2015/11/19 14:45:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10830 Hanoi Wave

10830 - Hanoi Wave   

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 from rod A to rod C, 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 moves of the disks. Print out character C of length K. K is 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


Given character C = '#', 

since the number of disk which is moved in each step is (1,2,1,3,1,2,1), you need to print one # in the first line, two # in the second line and one # in the third line and so on.

That is

#
##
#
###
#
##
#


Note that

1.      This problem involves three files.

  • function.h: Function definition of hanoi.
  • function.cpp: Function describe of hanoi.
  • main.cpp: A driver program to test your implementation.

You will be provided with main.cpp and function.h, and asked to implement function.cpp.

2.     For OJ submission:

       Step 1. Submit only your function.cpp into the submission block. (Please choose c++ compiler) 

       Step 2. Check the results and debug your program if necessary.

function.h

#ifndef FUNCTION_H
#define FUNCTION_H
void hanoi(char c,int n, char A, char B, char C);
#endif

main.cpp

#include <stdio.h>
#include "function.h"

int main(){
    int n;
    char c;
    scanf("%c %d", &c,&n);
    hanoi(c,n, 'A', 'B', 'C');
    return 0;
}

Input

There are two inputs, separated by a space. The first one is a character C; the second one is an integer n (0<n<=10), which means the number of disk.

Output

Print out character C of length K. K is the number of disk which is moved in each step , and there is a '\n' at the end of each line.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

10830.cpp

Partial Judge Header

10830.h

Tags

10401Contest



Discuss