Advertisement
Guest User

Untitled

a guest
Jun 14th, 2020
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. <?php
  2.  
  3. interface CitizenInterface
  4. {
  5.  
  6. public function setId(): void ;
  7. }
  8.  
  9. class Citizens implements CitizenInterface
  10. {
  11. /**
  12. * @var string
  13. */
  14. private $name;
  15. /**
  16. * @var int
  17. */
  18. private $age;
  19. /**
  20. * @var string
  21. */
  22. private $id;
  23.  
  24. /**
  25. * Citizens constructor.
  26. * @param string $name
  27. * @param int $age
  28. * @param string $id
  29. */
  30. public function __construct(string $name, int $age,string $id)
  31. {
  32. $this->name = $name;
  33. $this->age = $age;
  34. $this->id=$id;
  35. }
  36.  
  37. /**
  38. * @return string
  39. */
  40. public function getName(): string
  41. {
  42. return $this->name;
  43. }
  44.  
  45. /**
  46. * @param string $name
  47. */
  48. public function setName(string $name): void
  49. {
  50. $this->name = $name;
  51. }
  52.  
  53. /**
  54. * @return int
  55. */
  56. public function getAge(): int
  57. {
  58. return $this->age;
  59. }
  60.  
  61. /**
  62. * @param int $age
  63. */
  64. public function setAge(int $age): void
  65. {
  66. $this->age = $age;
  67. }
  68.  
  69. /**
  70. * @return string
  71. */
  72. public function getId(): string
  73. {
  74. return $this->id;
  75. }
  76.  
  77. public function setId(): void
  78. {
  79. $this->setId();
  80. }
  81. }
  82.  
  83. class Robot implements CitizenInterface
  84. {
  85. /**
  86. * @var string
  87. */
  88. private $model;
  89. /**
  90. * @var string
  91. */
  92. private $id;
  93. /**
  94. * Robot constructor.
  95. * @param string $model
  96. * @param string $id
  97. */
  98. public function __construct(string $model,string $id)
  99. {
  100. $this->model = $model;
  101. $this->id = $id;
  102. }
  103. /**
  104. * @return string
  105. */
  106. public function getModel(): string
  107. {
  108. return $this->model;
  109. }
  110.  
  111. /**
  112. * @return string
  113. */
  114. public function getId(): string
  115. {
  116. return $this->id;
  117. }
  118. public function setId(): void
  119. {
  120. $this->setId();
  121. }
  122. }
  123.  
  124. class Main
  125. {
  126. /**
  127. * @var array
  128. */
  129. private $citizen;
  130.  
  131. public function run()
  132. {
  133. $this->readData();
  134. }
  135.  
  136. const PATTERN = '/\s+/';
  137.  
  138. public function readData()
  139. {
  140. $line = readline();
  141. while ($line != "End") {
  142. $input = preg_split(self::PATTERN, $line, -1);
  143. if (count($input) == 3) {
  144. $name = $input[0];
  145. $age = $input[1];
  146. $id = $input[2];
  147. $this->citizen[] = new Citizens($name, $age, $id);
  148. }
  149. elseif (count($input) == 2) {
  150. $model = $input[0];
  151. $id = $input[1];
  152. $this->citizen[] = new Robot($model,$id);
  153. }
  154. $line = readline();
  155. }
  156. /**
  157. * @var Citizen $item
  158. * @var Robot $item
  159. */
  160. $line = readline();
  161. $str = "";
  162. foreach ($this->citizen as $item) {
  163. $pos = strrpos($item->getId(), $line);
  164. if ($pos) {
  165. $str .= $item->getId() . "\n";
  166. }
  167. }
  168. echo trim($str, "\n");
  169. // print_r($this->citizen);
  170. }
  171. }
  172.  
  173. $main = new Main();
  174. $main->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement