#K13311. Average Temperature Calculation
Average Temperature Calculation
Average Temperature Calculation
You are given a dataset of weather records. Each record contains a timestamp, a region identifier, and a temperature measurement. Your task is to compute the average temperature for a specified region over a given time period.
The timestamp follows the format \(\texttt{YYYY-MM-DD HH:MM:SS}\). Given a region name, a start time, and an end time, you must consider only the records that match the region and whose timestamps fall within the inclusive range of the start and end times. If there are no matching records, output None
. Otherwise, output the average temperature rounded to two decimal places.
For example, if the records are:
2023-04-01 01:00:00 North 20.0 2023-04-01 02:00:00 North 22.0 2023-04-01 03:00:00 North 24.0 2023-04-01 01:00:00 South 25.0
and the input query is North
with a start time of 2023-04-01 01:00:00
and an end time of 2023-04-01 03:00:00
, then the answer is 22.0
.
inputFormat
The input is read from standard input (stdin) with the following format:
- The first line contains an integer \(N\) representing the number of records.
- The next \(N\) lines each contain a record with four fields separated by spaces: a date (\(YYYY-MM-DD\)), a time (\(HH:MM:SS\)), a region (a string without spaces), and a temperature (a floating-point number). Note that the first two fields together form the timestamp.
- The following line contains the target region (a string).
- The next line contains the start time (in the format \(YYYY-MM-DD HH:MM:SS\)).
- The last line contains the end time (in the format \(YYYY-MM-DD HH:MM:SS\)).
outputFormat
If there are records matching the given region within the specified time period, output the average temperature rounded to two decimal places. Otherwise, output None
(without quotes).
4
2023-04-01 01:00:00 North 20.0
2023-04-01 02:00:00 North 22.0
2023-04-01 03:00:00 North 24.0
2023-04-01 01:00:00 South 25.0
North
2023-04-01 01:00:00
2023-04-01 03:00:00
22.00