Acceleration: The Second Difference
A test vehicle at Riverbend Supply's depot logs its speed once a second. The engineers are not interested in the speed itself, nor even in how fast it was picking up — they want to know whether the pick-up was itself getting stronger or easing off, because that is what shows a gearbox slipping. A vehicle gaining an extra 5 mph each second is behaving quite differently from one gaining a steady 10 mph each second, even though both are speeding up. The first reading has no reading before it, and the reading after that has no earlier gain to be compared with, so the report is always two entries shorter than the log.
Task: Print how much the vehicle's gain in speed changed from one second to the next.
Input
The first line holds a single integer n, the number of speed readings; n is at least 3. Each of the next n lines holds one speed, in time order, which may carry decimals.
Output
One line holding n - 2 values, in time order, separated by single spaces, each with two digits after the decimal point. A positive value means the pick-up strengthened; a negative one means it eased off; zero means it held steady.
Example:
Input:
4
0
10
25
45
Output:
5.00 5.00
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in