#C6971. Sort Animals by Multiple Criteria
Sort Animals by Multiple Criteria
Sort Animals by Multiple Criteria
You are given a list of animals, each described by four attributes: name (a string), age (an integer), weight (a floating-point number), and height (a floating-point number). Your task is to sort these animals according to the following rules:
- Sort primarily by age in descending order.
- If two animals have the same age, sort them by weight in ascending order.
- If both age and weight are the same, sort them by height in ascending order.
In other words, if we denote age by \(a\), weight by \(w\), and height by \(h\), you must sort the list according to the key:
[ \text{key} = (-a, w, h), ]
Implement the solution so that it reads from the standard input (stdin) and writes the result to the standard output (stdout).
inputFormat
The input begins with a single integer n
(\(0 \leq n \leq 10^5\)) representing the number of animals. Each of the following n
lines contains the description of an animal in the format:
name age weight height
where:
name
is a string without spaces.age
is an integer.weight
andheight
are floating-point numbers.
outputFormat
Output the sorted list of animals, one per line, in the same format as the input:
name age weight height
No extra spaces or lines should be printed.
## sample5
elephant 10 5000.0 3.0
giraffe 5 800.0 5.0
monkey 5 35.0 1.0
tiger 3 200.0 1.1
elephant 5 5000.0 3.1
elephant 10 5000.0 3.0
monkey 5 35.0 1.0
giraffe 5 800.0 5.0
elephant 5 5000.0 3.1
tiger 3 200.0 1.1
</p>