873 - EECS_I2P(I)2015_Chen_Lab7&8 Scoreboard

Time

2015/11/25 08:20:00 2015/11/25 09:40:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10833 Permutations of Set
10843 Fibonacci number

10833 - Permutations of Set   

Description

Given a set of n≧1 elements, the problem is to print all possible permutations of this set. For example, if the set is (1,2,3), then the set of permutations is {(1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,2,1), (3,1,2)}.

 

<Hint1>

Looking at the case of four elements (1,2,3,4). The answer can be constructed by writing

  1. ‘1’ followed by all the permutations of (2,3,4)
  2. ‘2’ followed by all the permutations of (1,3,4)
  3. ‘3’ followed by all the permutations of (1,2,4)
  4. ‘4’ followed by all the permutations of (1,2,3)

 

<Hint2>

A recursive method to implement the above idea is as follows:

Consider the case of (1,2,3,4), that is, n=4.

  1. Place the set elements in a global array, and set the position index “k” as 0.
  2. Use a for-loop to “swap” (or exchange) the 1st element with the 1st element, the 2nd element, the 3rd element, and the 4th element, respectively.
    • In each loop-iteration:
      1. increment the position index “k” by 1 (for considering only the remaining elements in the following recursive call);
      2. use the updated k to recursively call your permutation function;
      3. note that because you use a global array, remember to swap back the two elements after the iteration.
  3. In a recursive-call path, when k reaches n, it means that you get a possible permutation.

 

Note that

1.      This problem involves three files.

  • function.h: Function definition of show, Swap and Perm.
  • function.c: Function describe of show, Swap and Perm.
  • main.c: A driver program to test your implementation.

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

2.     For OJ submission:

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

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

function.h

main.c

function.c

Input

The decimal number n that represents the number of elements in the set.

(1≦n≦5)

Output

In the output you should print all the permutations.

Be sure to add a newline character '\n' at the end of each line.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10833.c

Partial Judge Header

10833.h

Tags

10401HW8



Discuss




10843 - Fibonacci number   

Description

The  Fibonacci sequence are the numbers in the following intergur sequence:

 

0,\;1,\;1,\;2,\;3,\;5,\;8,\;13,\;21,\;34,\;55,\;89,\;144,\; \ldots\; In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the first two numbers in the Fibonacci sequence are  0 and 1, and each subsequent number is the sum of the previous two.

F_n = F_{n-1} + F_{n-2},\!\,       

F_0 = 0,\; F_1 = 1.

You should enter a index of Fibonacci sequence ,and then output a  Fibonacci numbers of this index 

Ex:  input 0 outout 0

       input 1 outout 1

       input 2 outout 1

       input 3 outout 2  etc..

 

Note that

1.      This problem involves three files.

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

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

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

int Fibr(int index);

#endif

main.c

#include <stdio.h>
#include "function.h"
int main(void)
{
    int index,n,i;
    scanf("%d",&index);
    n=Fibr(index);
    printf("index = %d,  Fibonacci numbers = %d",index,n);

    return 0;
}

Input

The decimal number index that indicates the number of  Fibonacci sequence.

0 ≤ index ≤ 35

Output

You should output of this index is what number.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10843.c

Partial Judge Header

10843.h

Tags




Discuss