Advertisement
ShadowEmbrace

MOBA Challenger

Dec 12th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. <?php
  2.  
  3. $playerPool = [];
  4.  
  5. $input = readline();
  6.  
  7. while ($input !== 'Season end') {
  8.  
  9.     if (strpos($input, ' vs ') !== false) {
  10.         list($player1, $player2) = explode(' vs ', $input);
  11.  
  12.         if (key_exists($player1, $playerPool) && key_exists($player2, $playerPool)) {
  13.             foreach ($playerPool[$player1] as $role => $power) {
  14.                 if (key_exists($role, $playerPool[$player2])) {
  15.                     if ($playerPool[$player1][$role] > $playerPool[$player2][$role]) {
  16.                         unset($playerPool[$player2]);
  17.                         break;
  18.                     } elseif ($playerPool[$player2][$role] > $playerPool[$player1][$role]) {
  19.                         unset($playerPool[$player1]);
  20.                         break;
  21.                     }
  22.                 }
  23.             }
  24.         }
  25.     } else {
  26.         list($player, $position, $skill) = explode(' -> ', $input);
  27.  
  28.         if (!key_exists($player, $playerPool)) {
  29.             $playerPool[$player] = [];
  30.         }
  31.         if (!key_exists($position, $playerPool[$player])) {
  32.             $playerPool[$player][$position] = 0;
  33.         }
  34.         if ($playerPool[$player][$position] < $skill) {
  35.             $playerPool[$player][$position] = $skill;
  36.         }
  37.     }
  38.  
  39.     $input = readline();
  40. }
  41.  
  42. foreach ($playerPool as $playerD => $skillD) {
  43.     uksort($playerPool[$playerD], function ($key1, $key2) use ($skillD) {
  44.         if ($skillD[$key2] === $skillD[$key1]) {
  45.             return $key1 <=> $key2;
  46.         }
  47.         return $skillD[$key2] <=> $skillD[$key1];
  48.     });
  49.     $playerPool[$playerD]['totalSkill'] = 0;
  50.  
  51.     foreach ($skillD as $power) {
  52.         $playerPool[$playerD]['totalSkill'] += $power;
  53.     }
  54. }
  55.  
  56. uksort($playerPool, function ($pl1, $pl2) use ($playerPool) {
  57.     return $playerPool[$pl2]['totalSkill'] <=> $playerPool[$pl1]['totalSkill'];
  58. });
  59.  
  60. foreach ($playerPool as $playerT => $skill) {
  61.     echo $playerT . ": " . $playerPool[$playerT]['totalSkill'] . " skill" . PHP_EOL;
  62.     unset($playerPool[$playerT]['totalSkill']);
  63.  
  64.     foreach ($playerPool[$playerT] as $skillName => $value) {
  65.         echo "- $skillName <::> $value" . PHP_EOL;
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement