Click Here to see the problem detail.

Solution

Algorithm:

step1: If arrival time in hour<current time in hour

then arrival time in hour+24

explanation: let current time is 10:00 & bus arrives at 9:00 ! This means you missed today’s bus which departed at 9:00. So you have to wait until next day(24 hours)

step2 : If arrival time in minute<current time in minute

then arrival time in minute+60 & arrival time in hour-1

explanation: let current time is 4:15 & bus will arrive at 4:20. In this case do nothing in this step. but if   current time is 4:15 & bus will arrive at 5:10 then  arrival time in minute will be increased with 60 (10+60) & arrival time in hour will be reduced by 1 (5-1). Now we can calculate the time to arrive a bus as step3.

step3: How much time it will take to arrive bus=(arival time in hour – current time in hour) * 60 +(arival time in minute– current time in minute)

step4:How much time it will take to arrive home=How much time it will take to arrive bus(calculated in step two)+ traveling time.

step5:Find the lowest value of step4’s values. Show this lowest value as output

Source Code

 


Next Previous