Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = readline();
- $results = [];
- $submissions = [];
- while($input !== "exam finished") {
- $countDash = substr_count($input, "-");
- if($countDash > 1) {
- list($name, $techOrCommand, $points) = explode("-", $input);
- if(!key_exists($name, $submissions)) {
- $submissions[$name]['technology'] = $techOrCommand;
- $submissions[$name]['points'] = $points;
- }else {
- if($submissions[$name]['points'] < $points) {
- $submissions[$name]['points'] = $points;
- }
- }
- if(!key_exists($techOrCommand, $results)) {
- $results[$techOrCommand] = 1;
- }else {
- $results[$techOrCommand] ++;
- }
- }else {
- list($name) = explode("-", $input);
- if(key_exists($name, $submissions)) {
- unset($submissions[$name]);
- }
- }
- $input = readline();
- }
- uksort($submissions, function ($key1, $key2) use($submissions) {
- $points1 = $submissions[$key1]['points'];
- $points2 = $submissions[$key2]['points'];
- if($points1 === $points2) {
- return $key1 <=> $key2;
- }
- return $points2 <=> $points1;
- });
- uksort($results, function ($key1, $key2) use($results) {
- $count1 = $results[$key1];
- $count2 = $results[$key2];
- if($count1 === $count2) {
- return $key1 <=> $key2;
- }
- return $count2 <=> $count1;
- });
- echo "Results:".PHP_EOL;
- foreach ($submissions as $name => $points) {
- echo "$name | ".$points['points'].PHP_EOL;
- }
- echo "Submissions:".PHP_EOL;
- foreach ($results as $tech => $count) {
- echo "$tech - $count".PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment