Advertisement
Guest User

SoftUniKaraoke

a guest
Feb 3rd, 2020
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2. $participants = explode(", ", trim(readline()));
  3. $songs = explode(", ", trim(readline()));
  4. $input = readline();
  5. $args = [];
  6. // Vankata, Dragana - Kukavice, Best Srabsko
  7. while ($input != "dawn") {
  8.     $command = explode(", ", trim($input));
  9.     $singer = $command[0];
  10.     $song = $command[1];
  11.     $award = $command[2];
  12.     if (!in_array($singer, $participants) || !in_array($song, $songs)) {
  13.         $input = readline();
  14.         continue;
  15.     }
  16.     if (!key_exists($singer, $args) || !in_array($award, $args[$singer])) {
  17.         $args[$singer][] = $award;
  18.     }
  19.     $input = readline();
  20. }  
  21. if (count($args) == 0) {
  22.     echo "No awards";
  23.     return;
  24. }
  25. ksort($args);
  26. uasort($args, function ($a, $b) {
  27.     return count($b) - count($a);
  28. });
  29. foreach ($args as $key => $item) {
  30.     $awardCount = count($item);
  31.     echo "$key: $awardCount awards" . PHP_EOL;
  32.     sort($item);
  33.     foreach ($item as $value) {
  34.         echo "--$value" . PHP_EOL;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement