Advertisement
MartinGeorgiev

Cookie Factory

Apr 18th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2.  
  3. $batches = intval(readline());
  4. $hasFlour = false;
  5. $hasEggs = false;
  6. $hasSugar = false;
  7. for ($i = 1; $i <= $batches; $i++) {
  8.     while ($i<=$batches) {
  9.         $ingredient = readline();
  10.         if ($ingredient === "Bake!") {
  11.             if ($hasFlour && $hasEggs && $hasSugar) {
  12.                 $hasEggs = false;
  13.                 $hasFlour = false;
  14.                 $hasSugar = false;
  15.                 echo "Baking batch number $i..." . PHP_EOL;
  16.                 break;
  17.             }else {
  18.                 echo "The batter should contain flour, eggs and sugar!".PHP_EOL;
  19.             }
  20.            
  21.         } else {
  22.             if ($ingredient === "flour") {
  23.                 $hasFlour = true;
  24.             } else if ($ingredient === "eggs") {
  25.                 $hasEggs = true;
  26.             } else if ($ingredient === "sugar") {
  27.                 $hasSugar = true;
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement