fork(2) download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. /*
  6. Департамент закупок: 9×ме1, 3×ме2, 2×ме3, 2×ма1 + руководитель департамента ме2
  7. Департамент продаж: 12×ме1, 6×ма1, 3×ан1, 2×ан2 + руководитель ма2
  8. Департамент рекламы: 15×ма1, 10×ма2, 8×ме1, 2×ин1 + руководитель ма3
  9. Департамент логистики: 13×ме1, 5×ме2, 5×ин1 + руководитель ме1
  10. */
  11.  
  12.  
  13. class Employee {
  14. protected $baseSalary;
  15. protected $coffee;
  16. protected $reports;
  17. protected $rank;
  18. protected $isHead;
  19.  
  20. public function __construct($rank, $isHead) {
  21. $this->rank = $rank;
  22. $this->isHead = $isHead;
  23. }
  24.  
  25. public function getSalary() {
  26. $salary = $this->baseSalary;
  27. switch ($this->rank) {
  28. case 2:
  29. $salary *= 1.25;
  30. break;
  31. case 3:
  32. $salary *= 1.5;
  33. break;
  34. }
  35. if ($this->isHead) {
  36. $salary *= 1.5;
  37. }
  38.  
  39. return $salary;
  40. }
  41.  
  42. public function setBaseSalary($newSalary) {
  43. $this->baseSalary = $newSalary;
  44. }
  45.  
  46. public function getCoffee() {
  47. if ($this->isHead) {
  48. return $this->coffee * 2;
  49. } else {
  50. return $this->coffee;
  51. }
  52. }
  53.  
  54. public function setCoffe($newCoffee) {
  55. $this->coffee = $newCoffee;
  56. }
  57.  
  58. public function getReports() {
  59. if ($this->isHead) {
  60. return 0;
  61. } else {
  62. return $this->reports;
  63. }
  64. }
  65.  
  66. public function getRank()
  67. {
  68. return $this->rank;
  69. }
  70. public function setRank($rank)
  71. {
  72. $this->rank = $rank;
  73. }
  74. public function getIsHead()
  75. {
  76. return $this->isHead;
  77. }
  78. public function setIsHead($isHead)
  79. {
  80. $this->isHead = $isHead;
  81. }
  82.  
  83. }
  84.  
  85. class Manager extends Employee {
  86. protected $baseSalary = 500;
  87. protected $coffee = 20;
  88. protected $reports = 200;
  89. }
  90.  
  91. class Marketer extends Employee {
  92. protected $baseSalary = 400;
  93. protected $coffee = 15;
  94. protected $reports = 150;
  95. }
  96.  
  97. class Engineer extends Employee {
  98. protected $baseSalary = 200;
  99. protected $coffee = 5;
  100. protected $reports = 50;
  101. }
  102.  
  103. class Analyst extends Employee {
  104. protected $baseSalary = 800;
  105. protected $coffee = 50;
  106. protected $reports = 5;
  107. }
  108.  
  109. class Department {
  110. private $name;
  111. private $employees = array();
  112.  
  113. public function __construct($name) {
  114. $this->name = $name;
  115. }
  116.  
  117. function __clone() { //------------------------
  118. foreach ($this->employees as &$employee) {
  119. $employee = clone $employee;
  120. } //------------------------
  121. }
  122.  
  123. public function getName() {
  124. return $this->name;
  125. }
  126. public function setName($name) {
  127. $this->name = $name;
  128. }
  129.  
  130. public function getCountAllEmployees() {
  131. return count($this->employees);
  132. }
  133.  
  134. public function getAllEmployees() {
  135. return $this->employees;
  136. }
  137.  
  138. public function getAllSalary() {
  139. $allSalary = 0;
  140. foreach ($this->employees as $employee) {
  141. $allSalary += $employee->getSalary();
  142. }
  143. return $allSalary;
  144. }
  145.  
  146. public function getAllCoffee() {
  147. $allCoffee = 0;
  148. foreach ($this->employees as $employee) {
  149. $allCoffee += $employee->getCoffee();
  150. }
  151. return $allCoffee;
  152. }
  153.  
  154. public function getAllReports() {
  155. $allReports = 0;
  156. foreach ($this->employees as $employee) {
  157. $allReports += $employee->getReports();
  158. }
  159. return $allReports;
  160. }
  161.  
  162. public function addEmployees($employees) {
  163. $this->employees = array_merge($this->employees, $employees);
  164. }
  165.  
  166. public function fireEmployee($looser) {
  167. $fired = null;
  168. foreach($this->employees as $key => $employee) {
  169. if ($looser == $employee) {
  170. $fired = $looser;
  171. unset($this->employees[$key]);
  172. sort($this->employees);
  173. return $fired;
  174. }
  175. }
  176. return null;
  177. }
  178. }
  179.  
  180. function createManagers($quantity, $rank, $isHead) {
  181. $employees = array();
  182. for ($i = 0; $i < $quantity; $i++) {
  183. array_push($employees, new Manager($rank, $isHead));
  184. }
  185. return $employees;
  186. }
  187.  
  188. function createMarketers($quantity, $rank, $isHead) {
  189. $employees = array();
  190. for ($i = 0; $i < $quantity; $i++) {
  191. array_push($employees, new Marketer($rank, $isHead));
  192. }
  193. return $employees;
  194. }
  195.  
  196. function createEngineers($quantity, $rank, $isHead) {
  197. $employees = array();
  198. for ($i = 0; $i < $quantity; $i++) {
  199. array_push($employees, new Engineer($rank, $isHead));
  200. }
  201. return $employees;
  202. }
  203.  
  204. function createAnalysts($quantity, $rank, $isHead) {
  205. $employees = array();
  206. for ($i = 0; $i < $quantity; $i++) {
  207. array_push($employees, new Analyst($rank, $isHead));
  208. }
  209. return $employees;
  210. }
  211.  
  212. function padRight($string, $length) {
  213. $spacesCount = $length - mb_strlen($string);
  214. $string .= str_repeat(" ", $spacesCount);
  215. return $string;
  216. }
  217.  
  218. function padLeft($string, $length) {
  219. $modString = "";
  220. $spacesCount = $length - mb_strlen($string);
  221. $modString .= str_repeat(" ", $spacesCount);
  222. $modString .= $string;
  223. return $modString;
  224. }
  225.  
  226. function outputString($words) {
  227. $col = 11;
  228.  
  229. echo padRight($words[0], $col);
  230.  
  231. for ($i = 1; $i < count($words); $i++) {
  232. echo padLeft($words[$i], $col);
  233. }
  234. echo "\n";
  235. }
  236.  
  237. function outputResult($departments) {
  238. $totalEmployees = 0;
  239. $totalSalary = 0;
  240. $totalCoffee = 0;
  241. $totalReports = 0;
  242. $totalConsumption = 0;
  243.  
  244. $words = array("Департамент", "сотр.", "тугр.", "кофе", "стр.", "тугр./стр.");
  245. outputString($words);
  246.  
  247. echo str_repeat("-", 70);
  248. echo "\n";
  249.  
  250. foreach ($departments as $department) {
  251.  
  252. $employeesCount = $department->getCountAllEmployees();
  253. $totalEmployees += $employeesCount;
  254.  
  255. $salary = $department->getAllSalary();
  256. $totalSalary += $salary;
  257.  
  258. $coffee = $department->getAllCoffee();
  259. $totalCoffee += $coffee;
  260.  
  261. $reports = $department->getAllReports();
  262. $totalReports += $reports;
  263.  
  264. $consumption = round($salary / $reports, 2);
  265. $totalConsumption += $consumption;
  266.  
  267. $words = array($department->getName(), $employeesCount, $salary, $coffee, $reports, $consumption);
  268. outputString($words);
  269. }
  270.  
  271. echo "\n";
  272.  
  273. $countDepartments = count($departments);
  274. $words = array("Среднее", $totalEmployees / $countDepartments, $totalSalary / $countDepartments, $totalCoffee / $countDepartments,
  275. $totalReports / $countDepartments, $totalConsumption / $countDepartments);
  276. outputString($words);
  277.  
  278. $words = array("Всего", $totalEmployees, $totalSalary, $totalCoffee, $totalReports, $totalConsumption);
  279. outputString($words);
  280. }
  281.  
  282. $employees = array();
  283. $departments = array();
  284.  
  285. $employees = array_merge($employees, createManagers(9, 1, false), createManagers(3, 2, false),
  286. createManagers(2, 3, false), createMarketers(2, 1, false), createManagers(1, 2, true));
  287.  
  288. $purchases = new Department("Закупок");
  289. $purchases->addEmployees($employees);
  290.  
  291. array_push($departments, $purchases);
  292.  
  293. $employees = array();
  294. $employees = array_merge($employees, createManagers(12, 1, false), createMarketers(6, 1, false),
  295. createAnalysts(3, 1, false), createAnalysts(2, 2, false), createMarketers(1, 2, true));
  296.  
  297. $sales = new Department("Продаж");
  298. $sales->addEmployees($employees);
  299.  
  300. array_push($departments, $sales);
  301.  
  302. $employees = array();
  303. $employees = array_merge($employees, createMarketers(15, 1, false), createMarketers(10, 2, false),
  304. createManagers(8, 1, false), createEngineers(2, 1, false), createMarketers(1, 3, true));
  305.  
  306. $ad = new Department("Рекламы");
  307. $ad->addEmployees($employees);
  308.  
  309. array_push($departments, $ad);
  310.  
  311. $employees = array();
  312. $employees = array_merge($employees, createManagers(13, 1, false), createManagers(5, 2, false),
  313. createEngineers(5, 1, false), createManagers(1, 1, true));
  314.  
  315. $logistics = new Department("Логистики");
  316. $logistics->addEmployees($employees);
  317.  
  318. array_push($departments, $logistics);
  319.  
  320. outputResult($departments);
  321.  
  322. echo "\n\nАнтикризисные меры:\n\n"; //------------------------------------------------------------------------------------
  323.  
  324. $testDepartments = array();
  325.  
  326. echo "1. Сократить в каждом департаменте 40% инженеров:\n\n";
  327.  
  328. foreach ($departments as $department) {
  329. $countEng = 0;
  330. $testDepartment = clone $department;
  331. $employees = $testDepartment->getAllEmployees();
  332. foreach ($employees as $employee) {
  333. if ($employee instanceof Engineer) {
  334. $countEng++;
  335. }
  336. }
  337.  
  338. $needFire = ceil($countEng * 0.4);
  339.  
  340. for ($i = 0; $i < $needFire; $i++) {
  341. for ($j = 0; $j < count($employees); $j++) {
  342. if ($employees[$j] instanceof Engineer && !$employees[$j]->getIsHead()) {
  343. $testDepartment->fireEmployee($employees[$j]);
  344. break;
  345. }
  346. }
  347. }
  348. array_push($testDepartments, $testDepartment);
  349. }
  350.  
  351. outputResult($testDepartments);
  352.  
  353. echo "\n2. Увеличить в целях стимуляции умственной деятельности базовую ставку аналитика:\n\n";
  354.  
  355. $testDepartments = array();
  356.  
  357. foreach ($departments as $department) {
  358. $testDepartment = clone $department;
  359. $employees = $testDepartment->getAllEmployees();
  360. $haveAnals = false;
  361. $firstAnal = null;
  362. foreach ($employees as $employee) {
  363. if ($employee instanceof Analyst) {
  364. $employee->setBaseSalary(1100);
  365. $employee->setCoffe(75);
  366. if ($firstAnal === null) {
  367. $haveAnals = true;
  368. $firstAnal = $employee;
  369. }
  370. }
  371.  
  372. if ($employee->getIsHead() && !($employee instanceof Analyst) && $haveAnals) {
  373. $employee->setIsHead(false);
  374. $firstAnal->setRank(3);
  375. $firstAnal->setIsHead(true);
  376. }
  377. }
  378. array_push($testDepartments, $testDepartment);
  379. }
  380.  
  381. outputResult($testDepartments);
  382.  
  383. /*echo "3. В каждом департаменте повысить 50% (округляя в большую сторону) менеджеров 1-го и 2-го ранга на один ранг с
  384.   целью расширить их полномочия:<br><br>";*/
  385. echo "\nОригинальная таблица:\n\n";
  386.  
  387. outputResult($departments);
Success #stdin #stdout 0.04s 52480KB
stdin
Standard input is empty
stdout
Департамент      сотр.      тугр.       кофе       стр. тугр./стр.
----------------------------------------------------------------------
Закупок             17     9612.5        350       3100        3.1
Продаж              24      13550        610       3325       4.08
Рекламы             36      16300        575       5450       2.99
Логистики           24      11375        425       3850       2.95

Среднее          25.25  12709.375        490    3931.25       3.28
Всего              101    50837.5       1960      15725      13.12


Антикризисные меры:

1. Сократить в каждом департаменте 40% инженеров:

Департамент      сотр.      тугр.       кофе       стр. тугр./стр.
----------------------------------------------------------------------
Закупок             17     9612.5        350       3100        3.1
Продаж              24      13550        610       3325       4.08
Рекламы             35      16100        570       5400       2.98
Логистики           22      10975        415       3750       2.93

Среднее           24.5  12559.375     486.25    3893.75     3.2725
Всего               98    50237.5       1945      15575      13.09

2. Увеличить в целях стимуляции умственной деятельности базовую ставку аналитика:

Департамент      сотр.      тугр.       кофе       стр. тугр./стр.
----------------------------------------------------------------------
Закупок             17     9612.5        350       3100        3.1
Продаж              24      16325        795       3470        4.7
Рекламы             36      16300        575       5450       2.99
Логистики           24      11375        425       3850       2.95

Среднее          25.25  13403.125     536.25     3967.5      3.435
Всего              101    53612.5       2145      15870      13.74

Оригинальная таблица:

Департамент      сотр.      тугр.       кофе       стр. тугр./стр.
----------------------------------------------------------------------
Закупок             17     9612.5        350       3100        3.1
Продаж              24      13550        610       3325       4.08
Рекламы             36      16300        575       5450       2.99
Логистики           24      11375        425       3850       2.95

Среднее          25.25  12709.375        490    3931.25       3.28
Всего              101    50837.5       1960      15725      13.12