emodev

bus

Dec 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. <?php
  2.  
  3. $passengersBeginnig= intval(readline());
  4. $numberBusStops= intval(readline());
  5. $countBusStops=0;
  6. $passengersInBus= $passengersBeginnig;
  7. while($countBusStops<$numberBusStops){
  8.   $countBusStops++;
  9.  
  10.    $passengersOut= intval(readline());
  11.    $passengersInBus-=$passengersOut;
  12.     $passengersEnter= intval(readline());
  13.      $passengersInBus+=$passengersEnter;
  14.     if($countBusStops%2==1){
  15.    $passengersInBus+=2;
  16.        
  17.     }
  18.     if($countBusStops%2==0){
  19.     $passengersInBus-=2;
  20.  
  21.     }    
  22. }
  23. echo "The final number of passengers is : $passengersInBus";
Add Comment
Please, Sign In to add comment