#K15596. Array Sorting Problem

    ID: 24391 Type: Default 1000ms 256MiB

Array Sorting Problem

Array Sorting Problem

You are given an integer \(n\) representing the size of an array, followed by \(n\) integers and a string \(order\). The \(order\) is either asc for ascending order or desc for descending order. Your task is to sort the given array according to the specified order.

Specifically, if order = asc, then the result should satisfy \(a_1 \le a_2 \le \cdots \le a_n\). If order = desc, then it should satisfy \(a_1 \ge a_2 \ge \cdots \ge a_n\).

The sorted array should be printed as a sequence of integers separated by a single space.

inputFormat

The input is provided through standard input (stdin) and consists of three parts:

  1. The first line contains an integer \(n\), the size of the array.
  2. The second line contains \(n\) space-separated integers. If \(n = 0\), this line will be empty.
  3. The third line contains a string that is either asc or desc, indicating the sort order.

outputFormat

Output the sorted array to standard output (stdout) as a sequence of integers separated by a single space.

## sample
5
3 1 4 1 5
asc
1 1 3 4 5