#C7864. Average Temperature Calculation
Average Temperature Calculation
Average Temperature Calculation
You are given temperature readings over several days. Some readings may be missing, which are represented by the value -9999
. Your task is to compute the average temperature from the valid readings. If all readings for a test case are missing, output -9999
.
The average temperature is computed as:
\( \text{average} = \frac{\sum_{i=1}^{k} T_i}{k} \)
where \(T_i\) are the valid temperature readings and \(k\) is the number of valid readings. Round the result to 2 decimal places.
Note: Process multiple test cases from standard input.
inputFormat
The first line of input contains an integer T
representing the number of test cases. Each test case consists of two lines:
- The first line contains an integer
n
, the number of days. - The second line contains
n
space-separated integers representing the temperature readings. A reading of-9999
indicates missing data.
Input is read from standard input.
outputFormat
For each test case, output the average temperature on a new line. If there are valid temperature readings, output the average rounded to 2 decimal places. If all readings in a test case are missing, output -9999
.
Output should be written to standard output.
## sample4
5
20 25 -9999 30 18
4
-9999 -9999 -9999 -9999
6
-9999 15 19 21 -9999 30
5
20 25 30 18 22
23.25
-9999
21.25
23.0
</p>