#C13663. Temperature Conversion and Statistics
Temperature Conversion and Statistics
Temperature Conversion and Statistics
This problem requires you to process a list of temperature readings in Celsius and perform both a conversion and summary statistics. You are given a set of tokens representing temperatures. Some tokens may be non-numeric, and these should be ignored. From the valid numeric entries, compute the maximum, minimum, and average temperature.
The conversion from Celsius (C) to Fahrenheit (F) is given by the formula: \(F = \frac{9}{5}C + 32\). Your program should output a JSON object with the keys max
, min
, and average
corresponding to the computed Fahrenheit values. If there are no valid numeric entries, all three values should be null
.
Example:
Input: 5 0 10 20 30 40</p>Output: {"max": 104.0, "min": 32.0, "average": 68.0}
inputFormat
The first line contains a single integer N representing the number of temperature entries. The second line contains N space-separated tokens. Each token may be a valid integer or floating point number (representing a temperature in Celsius), or an invalid entry which must be ignored.
outputFormat
Output a JSON object (as a string) with three keys: max
, min
, and average
, which represent the maximum, minimum, and average temperature in Fahrenheit respectively. The conversion from Celsius to Fahrenheit is done using the formula: \(F = \frac{9}{5}C + 32\). If there are no valid temperatures, output null
for all three fields.
5
0 10 20 30 40
{"max": 104.0, "min": 32.0, "average": 68.0}