Question: I need the program in C Language. Ferry Loading Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their

I need the program in C Language.
Ferry Loading Before bridges were common, ferries were used to transport cars across rivers. River ferries, unlike their larger cousins, run on a guide line and are powered by theriver's current. Cars drive onto the ferry from one end, the ferry crosses the river, andthe cars exit from the other end of the ferry. There is an l-meter-long ferry that crosses the river. A car may arrive at either river bank to be transported by the ferry to the opposite bank. The ferry travelscontinuously back and forth between the banks so long as it is carrying a car or thereis at least one car waiting at cither bank. Whenever the ferry arrives at one of thebanks, it unloads its cargo and loads up cars that are waiting to cross as long as theyfit on its deck. The cars are loaded in the order of their arrival and the ferry's deckaccommodates only one lane of cars. The ferry is initially on the left bank where ithad mechanical problems and it took quite some time to fix it. In the meantime, linesof cars formed on both banks that wait to cross the river. The first line of input contains c, the number of test cases. Each test case begins with the number l, a space and then the number m. m lines follow describing the carsthat arrive in this order to be transported. Each line gives the length of a car (incentimeters), and the bank at which the car awaits the ferry ("left" or "right"). For each test case, output one line giving the number of times the ferry has to cross the river in order to serve all waiting cars. Sample input 4 20 4 380 left 720 left 1340 right 1040 left 15 4 380 left 720 left 1340 right 1040 left 15 4 380 left 720 left 1340 left 1040 left15 4 380 right 720 right1340 right1040 right Output for sample input 3 3 5 6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
