Ordena un Vector V Y80100


Statement
 

pdf   zip   main.cc

A vector V is a vector that is composed of two parts:

v=x1x2x3x4xny1y2y3ymv = x_1 ~ x_2 ~ x_3 ~ x_4 \dots x_n ~ y_1 ~ y_2~ y_3 \dots y_m

such that x1xnx_1 \dots x_n is ordered in a strictly decreasing manner and y1ymy_1 \dots y_m is ordered in a strictly increasing manner. Furthermore, xn>y1x_n > y_1. Finally, we have that n,m>0n,m > 0. That is, neither part is empty.

We need to implement the function

void ordena(const vector<int>& v, int pos, vector<int>& r)

with the following specification:

PRE: vv is a vector V such that v3\mid \! v \! \mid \geq 3, pospos is the position of y1y_1 in vv and v=r\mid \! v \! \mid = \mid \! r \! \mid.

POST: The vector rr contains all the elements of the vector vv and is sorted.

Observation

You only need to send the function we ask for and the actions and functions that you define yourself. The rest will not be taken into account.

The operation sort from the stl library cannot be used.

Hint: knowing the position of y1y_1 can help you sort the vector in linear time.

IMPORTANT: You only need to submit the requested function, and possibly other necessary actions and functions. However, you must keep the type definitions and #includes.

Input

An undetermined number of vectors V with the following format: an integer indicating their size, then the vector V, then the position where y1y_1 is in vv and finally a vector rr of the same size as vv. Every vector V has size greater than or equal to 3.

Output

The vector rr is sorted and contains all the elements of vv.

Sample session
ENTRADA 1:
10
20 18 16 2 4 6 8 10 12 14
3

SORTIDA 1:
2 4 6 8 10 12 14 16 18 20



ENTRADA 2:
10
20 2 4 6 8 10 12 14 16 18
1

SORTIDA 2:
2 4 6 8 10 12 14 16 18 20



ENTRADA 3:
10
20 18 16 2 4 6 8 10 12 14
3

SORTIDA 3:
2 4 6 8 10 12 14 16 18 20



ENTRADA 4:
5
14 11 8 2 14
3

SORTIDA 4:
2 8 11 14 14



ENTRADA 5:
10
20 2 4 6 8 10 12 14 16 18
1

SORTIDA 5:
2 4 6 8 10 12 14 16 18 20
Information
Author
PRO1
Language
English
Translator
Original language
Catalan
Other languages
Catalan Spanish
Official solutions
C++
User solutions
C++