Advertisement
kristina111

Untitled

Feb 26th, 2017
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <?php
  2.  
  3. class Person{
  4.     public $name;
  5.     public $age;
  6.  
  7.     function __construct(string $name, int $age)
  8.     {
  9.         $this->name=$name;
  10.         $this->age = $age;
  11.     }
  12. }
  13.  
  14. $inp = trim(intval(fgets(STDIN)));
  15. $allp = [];
  16. $maxage = 0;
  17.  
  18. for ($i=0;$i<$inp;$i++) {
  19.     $info = explode(" ", trim(fgets(STDIN)));
  20.     $person = new Person($info[0], intval($info[1]));
  21.     if(array_key_exists($person->age, $allp)){
  22.         continue;
  23.     }
  24.     $allp[$person->age] = $person->name;
  25.     if($person->age > $maxage) {
  26.         $maxage = $person->age;
  27.     }
  28. }
  29.  
  30. echo $allp[$maxage] . " " . $maxage;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement