1064 - I2P CS 2016 Chen Lab3 Scoreboard

Time

2016/11/10 13:30:00 2016/11/10 14:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11195 Hanoi
11203 Perfect Number

11195 - Hanoi   

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 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 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


You should print out:

1
2
1
3
1
2
1

The following graph is an easy example when n = 3:

 「hanoi tower」的圖片搜尋結果

You only need to complete following function:

#include <stdio.h>
#include "function.h"
void hanoi(int n, char A, char B, char C)
{
    // Write your code here
}

You may refer to [11656 Simple Permutation] for the submission specifications.

Input

An integer n (0<n<20), which means the number of disk.

Output

Print out 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

11195.cpp

Partial Judge Header

11195.h

Tags




Discuss




11203 - Perfect Number   

Description

perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is,
the sum of its positive divisors excluding the number itself (其正因數的總和,但不包含自己本身)

Ex: is 6 a perfect number?
since 1,2,3 are proper positive divisors of 6 , and the sum of them = 1+2+3 = 6 

Thus , 6 is a perfect number 

The question is :

Given a integer number N, print out all the perfect number <= N

In this problem, you only need to implement a function called isPerfect(int n).

It returns 1 if the number is perfect number , otherwise returns 0.

Main program is below. It calls the function you implement and print out the results.

---------------------------------------------------------------------------------------------------------

#include <stdio.h>
//-------------------------------------------

// Implement the function here  

//-------------------------------------------
int main(){
    int N, i;
    scanf("%d",&N);
    for(i=1; i<=N; i++){
        if(1==isPerfect(i)) printf("%d\n",i);
    }
}

----------------------------------------------------------------------------------------------------------

 

Input

There is only a integer N. (N<=10000)

Output

All perfect numbers that are smaller or equal to N

Sample Input  Download

Sample Output  Download

Partial Judge Code

11203.c

Partial Judge Header

11203.h

Tags




Discuss