Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //$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";
- $input = fgets(STDIN);
- // get requested items
- $inputReq = strtok($input,"|");
- // get broughted items
- $inputBr = strtok("|");
- // store requested items to an array
- $str = strtok($inputReq, " ");
- for($i=0; $str !== false; $i++)
- {
- $requested[$i] = $str;
- $str = strtok(" ");
- }
- // store broughted items to an array
- $str = strtok($inputBr, " ");
- for($i=0; $str !== false; $i++)
- {
- $broughted[$i] = $str;
- $str = strtok(" ");
- }
- // check
- $count = 0;
- $quantity = 0;
- echo "<ul>";
- for($i=0; $i < count($requested); $i++)
- {
- for($k=0; $k < count($broughted); $k++)
- {
- if(strtolower($requested[$i]) == strtolower($broughted[$k]))
- {
- $count++;
- }
- }
- echo "<li>" . $requested[$i] . ":" . $count . "</li>";
- $quantity += $count;
- $count = 0;
- }
- $quantity = count($broughted) - $quantity;
- $percent = ($quantity / count($broughted)) * 100;
- echo "<li>Angry:" . round($percent, 0) . "%</li></ul>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement