kristina111

Untitled

Feb 25th, 2017
151
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.      * @return string
  15.      */
  16.     public function getName(): string
  17.     {
  18.         return $this->name;
  19.     }
  20.  
  21.     /**
  22.      * @param string $name
  23.      */
  24.     public function setName(string $name)
  25.     {
  26.         $this->name = $name;
  27.     }
  28.  
  29.     /**
  30.      * @return int
  31.      */
  32.     public function getAge(): int
  33.     {
  34.         return $this->age;
  35.     }
  36.  
  37.     /**
  38.      * @param int $age
  39.      */
  40.     public function setAge(int $age)
  41.     {
  42.         $this->age = $age;
  43.     }
  44.  
  45.  
  46.  
  47.  
  48. }
  49.  
  50. $inp = trim(intval(fgets(STDIN)));
  51. $allp = [];
  52. //$maxage = 0;
  53.  
  54. for ($i=0;$i<$inp;$i++) {
  55.     $info = explode(" ", trim(fgets(STDIN)));
  56.     $person = new Person($info[0], intval($info[1]));
  57.     $allp[] = $person;
  58. //    if($person->age > $maxage) {
  59. ////        $maxage = $person->age;
  60. //    }
  61. }
  62.  
  63. $oldestMember = getOldestMember($allp);
  64. echo $oldestMember->getName() . " " . $oldestMember->getAge();
  65.  
  66. function getOldestMember($allp):Person{
  67.     if(count($allp)>0){
  68.         $oldestMember = current($allp);
  69.         /** @var Person $member */
  70.         foreach ($allp as $member){
  71.             if($oldestMember->getAge()<$member->getAge()){
  72.                 $oldestMember = $member;
  73.             }
  74.         }
  75.         return $oldestMember;
  76.     }else{
  77.         throw new Exception("No members in the Family!");
  78.     }
  79. }
RAW Paste Data