Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $playerPool = [];
- $input = readline();
- while ($input !== 'Season end') {
- if (strpos($input, ' vs ') !== false) {
- list($player1, $player2) = explode(' vs ', $input);
- if (key_exists($player1, $playerPool) && key_exists($player2, $playerPool)) {
- foreach ($playerPool[$player1] as $role => $power) {
- if (key_exists($role, $playerPool[$player2])) {
- if ($playerPool[$player1][$role] > $playerPool[$player2][$role]) {
- unset($playerPool[$player2]);
- break;
- } elseif ($playerPool[$player2][$role] > $playerPool[$player1][$role]) {
- unset($playerPool[$player1]);
- break;
- }
- }
- }
- }
- } else {
- list($player, $position, $skill) = explode(' -> ', $input);
- if (!key_exists($player, $playerPool)) {
- $playerPool[$player] = [];
- }
- if (!key_exists($position, $playerPool[$player])) {
- $playerPool[$player][$position] = 0;
- }
- if ($playerPool[$player][$position] < $skill) {
- $playerPool[$player][$position] = $skill;
- }
- }
- $input = readline();
- }
- foreach ($playerPool as $playerD => $skillD) {
- uksort($playerPool[$playerD], function ($key1, $key2) use ($skillD) {
- if ($skillD[$key2] === $skillD[$key1]) {
- return $key1 <=> $key2;
- }
- return $skillD[$key2] <=> $skillD[$key1];
- });
- $playerPool[$playerD]['totalSkill'] = 0;
- foreach ($skillD as $power) {
- $playerPool[$playerD]['totalSkill'] += $power;
- }
- }
- uksort($playerPool, function ($pl1, $pl2) use ($playerPool) {
- return $playerPool[$pl2]['totalSkill'] <=> $playerPool[$pl1]['totalSkill'];
- });
- foreach ($playerPool as $playerT => $skill) {
- echo $playerT . ": " . $playerPool[$playerT]['totalSkill'] . " skill" . PHP_EOL;
- unset($playerPool[$playerT]['totalSkill']);
- foreach ($playerPool[$playerT] as $skillName => $value) {
- echo "- $skillName <::> $value" . PHP_EOL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement