1074 - I2P CS 2016 Chen HW9 Scoreboard

Time

2016/11/19 00:00:00 2016/11/26 00:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11219 Get your array and then sort it!
11220 Permutation

11219 - Get your array and then sort it!   

Description

[Partial Judge]

Given a sequence of integers, sort it in increasing order by implementing the function my_sort().

The main code and the header code are provided as below.

There are two functions defined in the header file:

  • int* readInput();
  • void my_sort(int* B);

Function int* readInput() is given. It will read the input numbers, save it into an array, say Seq, and finally return the address of the array.
The first element of array Seq is the number of integers to be sorted. The following elements are the integers.

Function void my_sort(int* B) is the one leaved for you to implement. It take in a single argument B of type int*, whose value is the address of the address of the array Seq.

* Note that the address of the array Seq is returned by the function int* readInput().
* Also, you should be care of the actual type of the variable you want to access to. Do not be confused with the function definition.
* When submitting your code, remember to set Language option to "C: -O2 -lm -std=c99"

Input

A line of N integers seperated by a space in between.

100 <= N <= 1000.

The value of integer falls in the range of [-1000, 1000].

Input is handled by the provided function int* readInput(). You don't need to worry about it.

Output

A line of sorted integers seperated by a space in between. No extra space after the last integer. An newline character ('\n') is appended at the end.

You don't need to worry about it. It is handled in the provided main function.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11219.c

Partial Judge Header

11219.h

Tags




Discuss




11220 - Permutation   

Description

Given a set of n>=1 elements, the problem is to print all possible permutations of this set.

For example, if n = 3, then the set is (1,2,3), and the set of permutations is

(1,2,3)

(1,3,2)

(2,1,3)

(2,3,1)

(3,2,1)

(3,1,2)

 

  • Whenever you want to swap an element, you should swap with the orginal set of the current index.
  • For example, the set after (2,3,1) should swap the 1st element, which is to swap with the origin set of current index 1, that is (1,2,3), rather than swap with (2,3,1) itself. And after swap 1 and 3 from (1,2,3), the result is (3,2,1).

 

A recursive method to implement this problem 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.

Input

An interger n (1=<n<=10) that represents the number of elements in the set.

Output

Print all permutations.

Note that you have to print a '\n' at the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss