Advertisement
VZhelev

RoYaL The Angry One

Jun 6th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php
  2. //$input = "lepa-brena vino rakia filence salatka|lepa-brena mile hamburgski purjola vino vino vino filence supa plikche topeno-sirene rakia rakia rakia rakia rakia rakia";
  3. $input = fgets(STDIN);
  4.  
  5. // get requested items
  6. $inputReq = strtok($input,"|");
  7.  
  8. // get broughted items
  9. $inputBr = strtok("|");
  10.  
  11. // store requested items to an array
  12. $str = strtok($inputReq, " ");
  13.  
  14. for($i=0; $str !== false; $i++)
  15. {
  16.     $requested[$i] = $str;
  17.     $str = strtok(" ");
  18. }
  19.  
  20. // store broughted items to an array
  21. $str = strtok($inputBr, " ");
  22.  
  23. for($i=0; $str !== false; $i++)
  24. {
  25.     $broughted[$i] = $str;
  26.     $str = strtok(" ");
  27. }
  28.  
  29. // check
  30. $count = 0;
  31. $quantity = 0;
  32.  
  33. echo "<ul>";
  34.  
  35. for($i=0; $i < count($requested); $i++)
  36. {
  37.     for($k=0; $k < count($broughted); $k++)
  38.     {
  39.         if(strtolower($requested[$i]) == strtolower($broughted[$k]))
  40.         {
  41.             $count++;
  42.         }
  43.     }
  44.     echo "<li>" . $requested[$i] . ":" . $count . "</li>";
  45.     $quantity += $count;
  46.     $count = 0;
  47. }
  48.  
  49. $quantity = count($broughted) - $quantity;
  50. $percent = ($quantity / count($broughted)) * 100;
  51.  
  52. echo "<li>Angry:" . round($percent, 0) . "%</li></ul>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement