#K80017. Temperature Monitor

    ID: 35437 Type: Default 1000ms 256MiB

Temperature Monitor

Temperature Monitor

You are required to implement a temperature monitoring system that keeps track of temperature readings over time and allows you to compute the average temperature over a given interval.

The system supports two primary operations:

  • addReading t v: Adds a temperature reading with timestamp t and temperature value v.
  • average t1 t2: Computes the average temperature for all readings with timestamps in the closed interval \( [t1, t2] \). The result should be output as a floating-point number rounded to 2 decimal places. If there are no readings in the specified interval, output 0.00.

The input ends when a line containing the word end is encountered. All operations before this termination command should be processed sequentially.

Note: The average is calculated using the formula \( \text{average} = \frac{\sum_{i=1}^{n} v_i}{n} \) where \( v_i \) are the temperature values within the given interval. The result must be rounded to two decimal places.

inputFormat

The input consists of multiple lines. Each line is one of the following commands:

  • addReading t v: Add a temperature reading where t (an integer) is the timestamp and v (an integer) is the temperature value.
  • average t1 t2: Calculate the average temperature for readings with timestamps between t1 and t2 (inclusive).
  • end: Indicates the end of the input.

Input is given via standard input (stdin).

outputFormat

For each average command, output a line containing the average temperature, rounded to 2 decimal places. The results should be printed in the order the average commands appear in the input on standard output (stdout).

## sample
addReading 1 30
addReading 2 25
addReading 3 28
average 1 2
addReading 4 32
average 1 4
average 3 4
end
27.50

28.75 30.00

</p>