Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- interface CitizenInterface
- {
- public function setId(): void ;
- }
- class Citizens implements CitizenInterface
- {
- /**
- * @var string
- */
- private $name;
- /**
- * @var int
- */
- private $age;
- /**
- * @var string
- */
- private $id;
- /**
- * Citizens constructor.
- * @param string $name
- * @param int $age
- * @param string $id
- */
- public function __construct(string $name, int $age,string $id)
- {
- $this->name = $name;
- $this->age = $age;
- $this->id=$id;
- }
- /**
- * @return string
- */
- public function getName(): string
- {
- return $this->name;
- }
- /**
- * @param string $name
- */
- public function setName(string $name): void
- {
- $this->name = $name;
- }
- /**
- * @return int
- */
- public function getAge(): int
- {
- return $this->age;
- }
- /**
- * @param int $age
- */
- public function setAge(int $age): void
- {
- $this->age = $age;
- }
- /**
- * @return string
- */
- public function getId(): string
- {
- return $this->id;
- }
- public function setId(): void
- {
- $this->setId();
- }
- }
- class Robot implements CitizenInterface
- {
- /**
- * @var string
- */
- private $model;
- /**
- * @var string
- */
- private $id;
- /**
- * Robot constructor.
- * @param string $model
- * @param string $id
- */
- public function __construct(string $model,string $id)
- {
- $this->model = $model;
- $this->id = $id;
- }
- /**
- * @return string
- */
- public function getModel(): string
- {
- return $this->model;
- }
- /**
- * @return string
- */
- public function getId(): string
- {
- return $this->id;
- }
- public function setId(): void
- {
- $this->setId();
- }
- }
- class Main
- {
- /**
- * @var array
- */
- private $citizen;
- public function run()
- {
- $this->readData();
- }
- const PATTERN = '/\s+/';
- public function readData()
- {
- $line = readline();
- while ($line != "End") {
- $input = preg_split(self::PATTERN, $line, -1);
- if (count($input) == 3) {
- $name = $input[0];
- $age = $input[1];
- $id = $input[2];
- $this->citizen[] = new Citizens($name, $age, $id);
- }
- elseif (count($input) == 2) {
- $model = $input[0];
- $id = $input[1];
- $this->citizen[] = new Robot($model,$id);
- }
- $line = readline();
- }
- /**
- * @var Citizen $item
- * @var Robot $item
- */
- $line = readline();
- $str = "";
- foreach ($this->citizen as $item) {
- $pos = strrpos($item->getId(), $line);
- if ($pos) {
- $str .= $item->getId() . "\n";
- }
- }
- echo trim($str, "\n");
- // print_r($this->citizen);
- }
- }
- $main = new Main();
- $main->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement