#K39487. Array Transformation
Array Transformation
Array Transformation
You are given an array of integers. Your task is to transform the array according to the following rules:
- If a number is even, divide it by 2.
- If a number is odd and greater than 10, subtract 5 from it.
- If a number is odd and less than or equal to 10, add 3 to it.
The transformed array should be printed as a sequence of space-separated numbers on one line. If the input array is empty, print nothing.
The rules can be summarized in mathematical notation as follows:
\[ f(x)= \begin{cases} \frac{x}{2} & \text{if } x \text{ is even},\\ x-5 & \text{if } x \text{ is odd and } x > 10,\\ x+3 & \text{if } x \text{ is odd and } x \leq 10. \end{cases} \]
inputFormat
The first line contains an integer n
, representing the number of elements in the array. The second line contains n
space-separated integers.
outputFormat
Output the transformed array as a sequence of space-separated integers on a single line. If the array is empty (n = 0
), output nothing.
6
4 11 5 8 13 7
2 6 8 4 8 10
</p>