Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Person
- {
- public $name;
- public $age;
- public function getAge() {
- return $this->age;
- }
- public function getName() {
- return $this->name;
- }
- public function __construct(string $name, int $age)
- {
- $this->name = $name;
- $this->age = $age;
- }
- public function __toString()
- {
- return $this->name . " - " . $this->age;
- }
- }
- $n = intval(fgets(STDIN));
- $people = [];
- for ($i = 0; $i < $n; $i++) {
- $input = explode(" ", trim(fgets(STDIN)));
- $people[] = new Person($input[0], $input[1]);
- }
- $filtered = array_filter($people, function (Person $person) {
- return $person->getAge() > 30;
- });
- usort($filtered, function (Person $a, Person $b) {
- return $a->getName() <=> $b->getName();
- });
- foreach ($filtered as $person) {
- echo $person . PHP_EOL;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement