Advertisement
Guest User

Untitled

a guest
Dec 20th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.83 KB | None | 0 0
  1. <?php
  2.  
  3. class Person
  4. {
  5. public $name;
  6. public $company;
  7. public $car;
  8. public $pokemon;
  9. public $parents;
  10. public $children;
  11.  
  12. /**
  13. * Person constructor.
  14. * @param $company
  15. * @param $car
  16. * @param $pokemon
  17. * @param $parents
  18. * @param $children
  19. */
  20. public function __construct($name = '', $company = '', $car = '', $pokemon = '', $parents = '', $children = '')
  21. {
  22. $this->name = $name;
  23. $this->company = $company;
  24. $this->car = $car;
  25. $this->pokemon = $pokemon;
  26. $this->parents = $parents;
  27. $this->children = $children;
  28. }
  29.  
  30. /**
  31. * @return string
  32. */
  33. public function getName()
  34. {
  35. return $this->name;
  36. }
  37.  
  38. /**
  39. * @return object
  40. */
  41. public function getCompany()
  42. {
  43. return $this->company;
  44. }
  45.  
  46. /**
  47. * @return object
  48. */
  49. public function getCar()
  50. {
  51. return $this->car;
  52. }
  53.  
  54. /**
  55. * @return object
  56. */
  57. public function getPokemon()
  58. {
  59. return $this->pokemon;
  60. }
  61.  
  62. /**
  63. * @return object
  64. */
  65. public function getParents()
  66. {
  67. return $this->parents;
  68. }
  69.  
  70. /**
  71. * @return string
  72. */
  73. public function getChildren()
  74. {
  75. return $this->children;
  76. }
  77.  
  78.  
  79.  
  80. /**
  81. * @param string $name
  82. */
  83. public function setName(string $name)
  84. {
  85. $this->name = $name;
  86. }
  87.  
  88. /**
  89. * @param Company $company
  90. */
  91. public function setCompany(Company $company)
  92. {
  93. $this->company = $company;
  94. }
  95.  
  96. /**
  97. * @param Car $car
  98. */
  99. public function setCar(Car $car)
  100. {
  101. $this->car = $car;
  102. }
  103.  
  104. /**
  105. * @param Pokemon $pokemon
  106. */
  107. public function setPokemon(Pokemon $pokemon)
  108. {
  109. $this->pokemon = $pokemon;
  110. }
  111.  
  112. /**
  113. * @param Parents $parents
  114. */
  115. public function setParents(Parents $parents)
  116. {
  117. $this->parents = $parents;
  118. }
  119.  
  120. /**
  121. * @param Children $children
  122. */
  123. public function setChildren(Children $children)
  124. {
  125. $this->children = $children;
  126. }
  127.  
  128.  
  129.  
  130. }
  131.  
  132. class Company
  133. {
  134. public $name;
  135. public $department;
  136. public $salary;
  137.  
  138. /**
  139. * Company constructor.
  140. * @param $name
  141. * @param $department
  142. * @param $salary
  143. */
  144. public function __construct($name = '', $department = '', $salary = '')
  145. {
  146. $this->name = $name;
  147. $this->department = $department;
  148. $this->salary = $salary;
  149. }
  150.  
  151. /**
  152. * @return string
  153. */
  154. public function getName(): string
  155. {
  156. return $this->name;
  157. }
  158.  
  159. /**
  160. * @return string
  161. */
  162. public function getDepartment(): string
  163. {
  164. return $this->department;
  165. }
  166.  
  167. /**
  168. * @return string
  169. */
  170. public function getSalary(): string
  171. {
  172. return $this->salary;
  173. }
  174.  
  175.  
  176. }
  177.  
  178. class Pokemon
  179. {
  180. public $name;
  181. public $element;
  182.  
  183. /**
  184. * Pokemon constructor.
  185. * @param $name
  186. * @param $element
  187. */
  188. public function __construct($name = '', $element = '')
  189. {
  190. $this->name = $name;
  191. $this->element = $element;
  192. }
  193.  
  194. /**
  195. * @return string
  196. */
  197. public function getName(): string
  198. {
  199. return $this->name;
  200. }
  201.  
  202. /**
  203. * @return string
  204. */
  205. public function getElement(): string
  206. {
  207. return $this->element;
  208. }
  209.  
  210.  
  211. }
  212.  
  213. class Parents
  214. {
  215. public $name;
  216. public $birthday;
  217.  
  218. /**
  219. * Parents constructor.
  220. * @param $name
  221. * @param $birthday
  222. */
  223. public function __construct($name = '', $birthday = '')
  224. {
  225. $this->name = $name;
  226. $this->birthday = $birthday;
  227. }
  228.  
  229. /**
  230. * @return string
  231. */
  232. public function getName(): string
  233. {
  234. return $this->name;
  235. }
  236.  
  237. /**
  238. * @return string
  239. */
  240. public function getBirthday(): string
  241. {
  242. return $this->birthday;
  243. }
  244.  
  245.  
  246. }
  247.  
  248. class Children
  249. {
  250. public $name;
  251. public $birthday;
  252.  
  253. /**
  254. * Children constructor.
  255. * @param $name
  256. * @param $birthday
  257. */
  258. public function __construct($name = '', $birthday = '')
  259. {
  260. $this->name = $name;
  261. $this->birthday = $birthday;
  262. }
  263.  
  264. /**
  265. * @return string
  266. */
  267. public function getName(): string
  268. {
  269. return $this->name;
  270. }
  271.  
  272. /**
  273. * @return string
  274. */
  275. public function getBirthday(): string
  276. {
  277. return $this->birthday;
  278. }
  279.  
  280.  
  281. }
  282.  
  283. class Car
  284. {
  285. public $model;
  286. public $speed;
  287.  
  288. /**
  289. * Car constructor.
  290. * @param $model
  291. * @param $speed
  292. */
  293. public function __construct($model = '', $speed = '')
  294. {
  295. $this->model = $model;
  296. $this->speed = $speed;
  297. }
  298.  
  299. /**
  300. * @return string
  301. */
  302. public function getModel(): string
  303. {
  304. return $this->model;
  305. }
  306.  
  307. /**
  308. * @return string
  309. */
  310. public function getSpeed(): string
  311. {
  312. return $this->speed;
  313. }
  314.  
  315. }
  316.  
  317. $persons = [];
  318.  
  319. while (true) {
  320. $inputLine = trim(fgets(STDIN));
  321.  
  322. if ($inputLine == 'End') {
  323. break;
  324. }
  325.  
  326. $inputLine = explode(' ', $inputLine);
  327. $personName = $inputLine[0];
  328. $class = $inputLine[1];
  329.  
  330. if (!in_array($personName, $persons)) {
  331. $person = new Person($personName);
  332. }
  333.  
  334. switch ($class) {
  335. case 'pokemon':
  336. $pokemonName = $inputLine[2];
  337. $pokemonElement = $inputLine[3];
  338. $pokemon = new Pokemon($pokemonName, $pokemonElement);
  339. $person->setPokemon($pokemon);
  340. break;
  341. case 'parents':
  342. $parentsName = $inputLine[2];
  343. $parentBirthday = $inputLine[3];
  344. $parents = new Parents($parentsName, $parentBirthday);
  345. $person->setParents($parents);
  346. break;
  347. case 'company':
  348. $companyName = $inputLine[2];
  349. $companyDepartment = $inputLine[3];
  350. $companySalary = $inputLine[4];
  351. $company = new Company($companyName, $companyDepartment, $companySalary);
  352. $person->setCompany($company);
  353. break;
  354. case 'children':
  355. $childrenName = $inputLine[2];
  356. $childrenBirthday = $inputLine[3];
  357. $children = new Children($childrenName, $childrenBirthday);
  358. $person->setChildren($children);
  359. break;
  360. case 'car':
  361. $carModel = $inputLine[2];
  362. $carSpeed = $inputLine[3];
  363. $car = new Car($carModel, $carSpeed);
  364. $person->setCar($car);
  365. break;
  366. }
  367.  
  368. if (!in_array($personName, $persons)) {
  369. $persons[$personName] = $person;
  370. }
  371.  
  372. }
  373.  
  374. $personOutput = trim(fgets(STDIN));
  375. $person = $persons[$personOutput];
  376. var_dump($persons); exit;
  377.  
  378. echo $personOutput . PHP_EOL . 'Company: ' . PHP_EOL .
  379. (is_object($person->getCompany()) ? $person->getCompany()->getName() : '') . PHP_EOL .
  380. 'Car: ' . PHP_EOL .
  381. (is_object($person->getCar()) ? $person->getCar()->getModel() : '') . PHP_EOL .
  382. 'Pokemon: ' . PHP_EOL .
  383. (is_object($person->getPokemon()) ? $person->getPokemon()->getName() : '') . PHP_EOL .
  384. 'Parents: ' . PHP_EOL .
  385. (is_object($person->getParents()) ? $person->getParents()->getName() : '') . PHP_EOL .
  386. 'Children: ' . PHP_EOL;
  387. (is_object($person->getChildren()) ? $person->getChildren()->getName() : '') . PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement