emotrend

Untitled

Dec 19th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2. $input = readline();
  3. $results = [];
  4. $submissions = [];
  5. while($input !== "exam finished") {
  6. $countDash = substr_count($input, "-");
  7. if($countDash > 1) {
  8. list($name, $techOrCommand, $points) = explode("-", $input);
  9. if(!key_exists($name, $submissions)) {
  10. $submissions[$name]['technology'] = $techOrCommand;
  11. $submissions[$name]['points'] = $points;
  12. }else {
  13. if($submissions[$name]['points'] < $points) {
  14. $submissions[$name]['points'] = $points;
  15. }
  16. }
  17. if(!key_exists($techOrCommand, $results)) {
  18. $results[$techOrCommand] = 1;
  19. }else {
  20. $results[$techOrCommand] ++;
  21. }
  22. }else {
  23. list($name) = explode("-", $input);
  24. if(key_exists($name, $submissions)) {
  25. unset($submissions[$name]);
  26. }
  27. }
  28. $input = readline();
  29. }
  30. uksort($submissions, function ($key1, $key2) use($submissions) {
  31. $points1 = $submissions[$key1]['points'];
  32. $points2 = $submissions[$key2]['points'];
  33. if($points1 === $points2) {
  34. return $key1 <=> $key2;
  35. }
  36. return $points2 <=> $points1;
  37. });
  38. uksort($results, function ($key1, $key2) use($results) {
  39. $count1 = $results[$key1];
  40. $count2 = $results[$key2];
  41. if($count1 === $count2) {
  42. return $key1 <=> $key2;
  43. }
  44. return $count2 <=> $count1;
  45. });
  46. echo "Results:".PHP_EOL;
  47. foreach ($submissions as $name => $points) {
  48. echo "$name | ".$points['points'].PHP_EOL;
  49. }
  50. echo "Submissions:".PHP_EOL;
  51. foreach ($results as $tech => $count) {
  52. echo "$tech - $count".PHP_EOL;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment