SHARE
TWEET

16. *Points Counter

DARIMI27 Jul 29th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $input = explode("|", readline());
  3. $sumValues = 0;
  4. $matrix = [];
  5. $sorted=[];
  6. $maxKee[]=0;
  7. while ($input[0] != "Result") {
  8.     $item = [];
  9.     foreach ($input as $item) {
  10.         $item = preg_replace("/[^a-zA-Z0-9]+/", "", $input);
  11.     }
  12.     if ((ctype_upper($item[0]))) {
  13.         $matrix[$item[0]][$item[1]] = intval($item[2]);
  14.     } else {
  15.         $matrix[$item[1]][$item[0]] = intval($item[2]);
  16.     }
  17.     $input = explode("|", readline());
  18. }
  19. foreach ($matrix as $key => $arr) {
  20.     $sumValues = 0;
  21.     $maxKey = 0;
  22.     foreach ($arr as $keyArr => $valueArr) {
  23.         $sumValues += $valueArr;
  24.         $sorted[$key]=$sumValues;
  25.         if ($valueArr>$maxKey){
  26.             $maxKey=$valueArr;
  27.         }
  28.         $keyR = array_search($maxKey, $arr);
  29.         $maxKee[$key]=$keyR;
  30.     }
  31. }
  32. arsort($sorted);
  33. foreach ($sorted as $key=>$value){
  34.     echo "$key" . " => " . $value . PHP_EOL;
  35.     echo "Most points scored by ".$maxKee[$key] . PHP_EOL;
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top