Advertisement
whitestarrr

Untitled

Feb 21st, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. class Person
  4. {
  5. public $name;
  6. public $age;
  7.  
  8. public function getAge() {
  9. return $this->age;
  10. }
  11.  
  12. public function getName() {
  13. return $this->name;
  14. }
  15.  
  16. public function __construct(string $name, int $age)
  17. {
  18. $this->name = $name;
  19. $this->age = $age;
  20. }
  21.  
  22. public function __toString()
  23. {
  24. return $this->name . " - " . $this->age;
  25. }
  26. }
  27.  
  28. $n = intval(fgets(STDIN));
  29. $people = [];
  30.  
  31. for ($i = 0; $i < $n; $i++) {
  32. $input = explode(" ", trim(fgets(STDIN)));
  33. $people[] = new Person($input[0], $input[1]);
  34. }
  35.  
  36. $filtered = array_filter($people, function (Person $person) {
  37. return $person->getAge() > 30;
  38. });
  39.  
  40. usort($filtered, function (Person $a, Person $b) {
  41. return $a->getName() <=> $b->getName();
  42. });
  43.  
  44. foreach ($filtered as $person) {
  45. echo $person . PHP_EOL;
  46. }
  47.  
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement