Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = readline();
- $dwarfs = [];
- while ($input !=="Once upon a time"){
- $args = explode(" <:> ", $input);
- $name = $args[0];
- $hatColor = $args[1];
- $physics = intval($args[2]);
- if (!key_exists($hatColor,$dwarfs)){
- $dwarfs[$hatColor][$name] = $physics;
- }
- elseif (key_exists($hatColor,$dwarfs) && key_exists($name,$dwarfs[$hatColor])){
- if ($dwarfs[$hatColor][$name]<$physics){
- $dwarfs[$hatColor][$name] = $physics;
- }
- }
- else {
- $dwarfs[$hatColor][$name] = $physics;
- }
- $input = readline();
- }
- foreach ($dwarfs as $hat=>$dwarfName){
- foreach ($dwarfName as $dName=>$power){
- echo "($hat) $dName <-> $power" .PHP_EOL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement