plamen911

11. Oldest Family Member

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