#C14991. Sorted Squares
Sorted Squares
Sorted Squares
Given a list of integers, compute a new list which contains the square of every integer in the original list, and then sort the new list in ascending order. For an input list ( A = [a_1, a_2, \dots, a_n] ), you need to produce a sorted list of squared values, i.e., sort ( [a_1^2, a_2^2, \dots, a_n^2] ) in non-decreasing order.
For example: if the input is 4 -3 2 1
then the squared values are [16, 9, 4, 1]
and the sorted result is 1 4 9 16
.
inputFormat
The input consists of a single line containing space-separated integers. It may be empty, in which case no output should be produced.
outputFormat
Output a single line containing the squares of the input integers sorted in ascending order, with each number separated by a single space.## sample
4 -3 2 1
1 4 9 16