Advertisement
bgdragoslav

Hello France

May 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2. $arr=explode("|",readline());
  3. $budget=readline();
  4. $j=0;
  5. $profit=0;
  6. $initialbudget=$budget;
  7. $prices=[];
  8. while($j<count($arr))
  9. {
  10.     $products=explode("->",$arr[$j]);
  11.     switch ($products[0])
  12.     {
  13.         case "Clothes":
  14.             if($products[1]>50);
  15.             else {
  16.                 if ($budget - $products[1] >= 0) {
  17.                     $budget -= $products[1];
  18.                     $profit += 1.4 * $products[1];
  19.                     $prices[] = 1.4 * $products[1];
  20.                 }
  21.             }
  22.             break;
  23.         case "Shoes":
  24.             if($products[1]>35) ;
  25.             else
  26.             {
  27.                 if($budget-$products[1] >= 0)
  28.                 {
  29.                     $budget-=$products[1];
  30.                     $profit+=1.4*$products[1];
  31.                     $prices[]=1.4*$products[1];
  32.                 }
  33.             }
  34.             break;
  35.         case "Accessories":
  36.             if($products[1]>20.5);
  37.             else {
  38.                 if ($budget - $products[1] >= 0) {
  39.                     $budget -= $products[1];
  40.                     $profit += 1.4 * $products[1];
  41.                     $prices[] = 1.4 * $products[1];
  42.                 }
  43.             }
  44.             break;
  45.         default:
  46.             $budget-=$products[1];
  47.             break;
  48.     }
  49.     if($budget<0) $budget+=$products[1];
  50.     $j++;
  51. }
  52. for($i=0;$i<count($prices);$i++)
  53. {
  54.     printf("%.2f ",$prices[$i]);
  55. }
  56. echo "\n";
  57. printf("Profit: %.2f\n",$profit+$budget-$initialbudget);
  58. if($profit+$budget>=150) echo "Hello, France!".PHP_EOL;
  59. else echo "Time to go.".PHP_EOL;
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement