Advertisement
KrasimiraGeorgieva

02.Тръби в басейн, Coding 101 Exam - 26 March 2016

Feb 4th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. // 100/100
  4. // вход  изход
  5. // 929   For 12 hours the pool overflows with 4399.0 liters.
  6. // 123
  7. // 321
  8. // 12
  9.  
  10. // 5946  The pool is 84% full. Pipe 1: 99%. Pipe 2: 0%.
  11. // 1000  
  12. // 1
  13. // 5
  14.  
  15. $volume = intval(readline());
  16. $firstFlowRate = intval(readline());  // liters/hour
  17. $secondFlowRate = intval(readline()); // liters/hour
  18. $hoursMiss = floatval(readline());
  19.  
  20. $firstDebit = $firstFlowRate * $hoursMiss;
  21. $secondDebit = $secondFlowRate * $hoursMiss;
  22. $totalDebit = $firstDebit + $secondDebit;
  23.  
  24. if ($totalDebit <= $volume) {
  25.     $full = floor(100 * $totalDebit / $volume);
  26.     $fullFirstPipe = floor(100 * $firstDebit / $totalDebit);
  27.     $fullSecondPipe = floor(100 * $secondDebit / $totalDebit);
  28.  
  29.     echo "The pool is $full% full. Pipe 1: $fullFirstPipe%. Pipe 2: $fullSecondPipe%.";
  30. } else {
  31.     $over = abs($volume - $totalDebit);
  32.    
  33.     echo "For $hoursMiss hours the pool overflows with " . number_format($over, 1, '.', '') . " liters.";
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement