SHARE
TWEET

Cookie Factory

MartinGeorgiev Apr 18th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top