2120 - IP_2020_YOU_HW5 Scoreboard

Time

2020/10/13 12:00:00 2020/10/20 12:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12905 GCD of Two Numbers
12906 Tower of Hanoi

12905 - GCD of Two Numbers   

Description

Given two natural numbers. Please write a C program to find out what is the greatest common divisor of these two natural numbers.

Hint: Use “Euclidean algorithms” (輾轉相除法).

Input

Two integers Num1, Num2.

Note that:

  1. 1 <= Num1, Num2 <= 32,767.

Output

Output should follow below format:

N

Note that:

  1. Need to have a return value('\n') at the end of your string.

Sample Input  Download

Sample Output  Download

Tags




Discuss




12906 - Tower of Hanoi   

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:

  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.

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. 1 <= N <= 16

Output

Output should follow below format:

Disk n moved from X to Y

Note that:

  1. Need to have a return value('\n') at the end of your string.
  2. n is the number of moving disk.
  3. 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.
 

Sample Input  Download

Sample Output  Download

Tags




Discuss