#K34397. Smooth Temperature Readings
Smooth Temperature Readings
Smooth Temperature Readings
You are given a series of temperature readings. Your task is to smooth the readings by replacing each temperature (except the first and the last) with the average of its two neighbors and itself. In other words, for an array of temperatures \(T_0, T_1, \dots, T_{n-1}\), if \(1 \le i \le n-2\), then the smoothed temperature \(T'_i\) is given by:
\( T'_i = \frac{T_{i-1} + T_i + T_{i+1}}{3} \)
The first and last temperature readings remain unchanged.
You need to implement this functionality reading inputs from stdin and sending the output to stdout.
inputFormat
The first line contains an integer (n) (the number of temperature readings). The second line contains (n) space-separated numbers (temperatures) which can be integers or floating-point numbers.
outputFormat
Output a single line containing (n) space-separated numbers representing the smoothed temperature readings. Note that if (n \le 2), the output is identical to the input.## sample
6
30 40 35 50 60 65
30 35.0 41.666666666666664 48.333333333333336 58.333333333333336 65