Median
Time limit1sMemory limit128 MB
For each group, print the middle value in input order, or the average of the two middle values when the count is even.
- Level
Easy1 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
The median of a group of values is the value in the middle. The count of values below the median equals the count above it.
Let the whole group be .
If is odd, the median is the value in position .
If is even, the median is the average of the values in positions and .
Positions follow the order in which the values appear in the input. Do not sort the values.
Input
Each line holds one group of values. The first integer on a line is , the number of values in that group, and the values follow it. Every value is an integer between and . The input has at most 100 lines, and one line holds at most 100 values. The last line holds a single 0 and marks the end of the input.
Output
For each group, print its median on its own line, in input order. Each line starts with Case n:, then one space, then the median. Here is the group number counting from 1. Print the median with one digit after the decimal point.