42. Train Crossing Time
Difficulty: easy · Math
Problem
A train must cover a total distance of 800 metres (a 400 m stretch of track plus a 400 m bridge). Given its speed in km/hr, compute the time it takes in seconds. Convert the speed to metres per second (multiply by `5/18`) and divide the distance by it; equivalently the time is `(800 / speed) * (18 / 5)` seconds. Print the time rounded to 2 decimal places (a third decimal of exactly 5 followed by nothing rounds up).
Input
A single line containing the integer `speed` in km/hr.
Output
Print the time in seconds with exactly two digits after the decimal point.
Example 1
Input: 72 Output: 40.00
Explanation: 72 km/hr is 20 m/s, and 800 / 20 = 40 seconds, printed as 40.00.
Example 2
Input: 7 Output: 411.43
Explanation: 2880 / 7 = 411.428..., which rounds to 411.43.
Constraints
- 1 <= speed <= 10^6
Solutions are judged against 2 sample and 10 hidden tests. Sign in to solve it · All problems