Module: Sorting with comparator


Problem

1/11

Vector sort: Start

Theory Click to read/hide

Sort with comparator
A vector (like an array)  can be sorted using the sort() function. But this function sorts in ascending order by default. To sort an array in a different order, you need to use the so-called comparator  - a function that sets the sort order by comparing two objects.
 
Example
An example of a comparator that sorts the elements of an array in ascending order. bool cmp(int first, int second) { return first < second; }
and sorting the vector A using the created comparator: sort(A.begin(), A.end(), cmp); Think about iterators

Problem

You are given a sequence of integers. Write a program that creates and sorts an array in descending order.
 
Input
First given number N — the number of elements in the array (1<=N<=100). Then N numbers are written separated by a space -  elements of the array. The array consists of integers.
 
Output
It is necessary to output an array sorted in descending order.
 
Examples
# Input Output
1 5
4 56 23 67 100
100 67 56 23 4