RareProgramming
How do you read three positive integers and print them in nonincreasing order?
Short answer
a ≥ b ≥ c
Explanation
In nonincreasing order each number is at most as large as the previous one. The reverse=True argument puts the greatest value first. The star in print unpacks the list into arguments, so the numbers appear separated by spaces.
The split() call separates the input at whitespace, so a space or a line break works. Converting each entry with int makes comparisons depend on its numerical value.
import sys
numbers = list(map(int, sys.stdin.read().split()))
print(*sorted(numbers, reverse=True))
Equal values must occur in the result as often as they occur in the input. Test 2 and 10 as well. Sorting numbers puts 10 before 2 here. Sorting the original strings would give a different result.
| Input | Check | Output |
|---|---|---|
| 2 10 4 | 10 ≥ 4 ≥ 2 | 10 4 2 |
| 9 4 9 | 9 ≥ 9 ≥ 4 | 9 9 4 |
| 3 3 3 | 3 ≥ 3 ≥ 3 | 3 3 3 |
Platforms
- MAXIMUM
