#K32952. Calculate Average Height
Calculate Average Height
Calculate Average Height
You are given a sequence of integers representing heights. The sequence terminates with the number -1, which should not be included in the computation. Your task is to compute the average of the valid heights and round the result to the nearest integer. However, if the average is exactly halfway between two integers, i.e. if \( \text{average} = a + 0.5 \) for some integer \( a \), you must round up to \( a+1 \).
Note: In many programming languages the typical rounding function (for example, round
in Python) uses "banker's rounding" (round half to even). In this problem, you have to implement rounding such that the tie (x.5) always rounds upward.
Example:
- If the heights are [160, 170, 180, 190, 200, -1], the average is 180.
- If the heights are [100, 200, -1], the average is 150 since \(150.0\) is exactly between 100 and 200, but it rounds up to 150.
inputFormat
The input is read from stdin
as a series of integers separated by spaces or newlines. The sequence is terminated by the integer -1, which should not be included in the average calculation.
outputFormat
Output a single integer to stdout
, which is the average height of the valid numbers, rounded according to the specified rule (ties rounded upward).
160 170 180 190 200 -1
180
</p>