fork download
  1. <?php
  2.  
  3. class Vector
  4. {
  5. public $employees;
  6. public $salary;
  7. public $coffee;
  8. public $pages;
  9.  
  10. private function countAll($qt, $rank, $salary, $coffee, $pages) {
  11. switch($rank) {
  12. case 1:
  13. $salary *= $qt;
  14. break;
  15. case 2:
  16. $salary += $salary*0.25;
  17. $salary *= $qt;
  18. break;
  19. case 3:
  20. $salary += $salary*0.5;
  21. $salary *= $qt;
  22. break;
  23. case 'leader':
  24. $salary += $salary*0.5;
  25. $coffee *= 2;
  26. $pages = 0;
  27. }
  28. $coffee *= $qt;
  29. $pages *= $qt;
  30. $results = [
  31. "employees" => $qt,
  32. "salary" => $salary,
  33. "coffee" => $coffee,
  34. "pages" => $pages
  35. ];
  36. return $results;
  37. }
  38. private function definePost($qt, $post, $rank) { //Определяет должность
  39. switch($post) {
  40. case 'ме': //Менеджер
  41. $salary = 500;
  42. $coffee = 20;
  43. $pages = 200;
  44. $results = $this->countAll($qt, $rank, $salary, $coffee, $pages);
  45. return $results;
  46. case 'ма': //Маркетолог
  47. $salary = 400;
  48. $coffee = 15;
  49. $pages = 150;
  50. $results = $this->countAll($qt, $rank, $salary, $coffee, $pages);
  51. return $results;
  52. case 'ин': //Инженер
  53. $salary = 200;
  54. $coffee = 5;
  55. $pages = 50;
  56. $results = $this->countAll($qt, $rank, $salary, $coffee, $pages);
  57. return $results;
  58. case 'ан': //Аналитик
  59. $salary = 800;
  60. $coffee = 50;
  61. $pages = 5;
  62. $results = $this->countAll($qt, $rank, $salary, $coffee, $pages);
  63. return $results;
  64. }
  65. }
  66. private function splitQtPostRank($qtPostRank) {
  67. $qt = preg_split('/х?ме|ма|ин|ан/u', $qtPostRank);
  68. if($qt[0] == "") {
  69. $qt[0] = 1;
  70. }
  71. $rank = $qt[1]; //Ранг
  72. $qt = $qt[0]; //Кол-во
  73. $pattern = ["/[0-9]/u", "/х/u"];
  74. $post = preg_filter($pattern, "",$qtPostRank); //Должность
  75. $qtPostRank = ["qt" => $qt, "post" => $post, "rank" => $rank];
  76. return $qtPostRank;
  77. }
  78. public function __construct($department) {
  79. $employeesTotal = 0;
  80. $salaryTotal = 0;
  81. $coffeeTotal = 0;
  82. $pagesTotal = 0;
  83. $results = [];
  84. $i = 0;
  85. foreach($department as $qtPostRank) {
  86. if(!preg_match('/([0-9]+)?+х?ме|ма|ин|ан[1-3]/u', $qtPostRank)) { //Проверка на соответствие шаблону
  87. die("Указанный параметр - неверный");
  88. }
  89. $qtPostRank = $this->splitQtPostRank($qtPostRank);
  90. $qt = $qtPostRank["qt"];
  91. $post = $qtPostRank["post"];
  92. $rank = $qtPostRank["rank"];
  93. $i++;
  94. if($i == count($department)-1) { //проверка на руководителя
  95. $rank = 'leader';
  96. }
  97. $results = $this->definePost($qt, $post, $rank);
  98. $employeesTotal += $results["employees"];
  99. $salaryTotal += $results["salary"];
  100. $coffeeTotal += $results["coffee"];
  101. $pagesTotal += $results["pages"];
  102. }
  103. $this->employees = $employeesTotal;
  104. $this->salary = $salaryTotal;
  105. $this->coffee = $coffeeTotal;
  106. $this->pages = $pagesTotal;
  107. }
  108. }
  109. //Предполагается, что последний элемент массива всегда руководитель департамента,
  110. //Департамент не может существовать без руководителя
  111. $purchaseDepartment = ['9хме1', '3хме2', '2хме3', 'ме2'];
  112. $sellingDepartment = ['12хме1','6хма1','3хан1','2хан2','ма2'];
  113. $advertisementDepartment = ['15хма1', '10хма2', '8хме1', '2хин1', 'ма3'];
  114. $logisticsDepartment = ['13хме1','5хме2','5хин1','ме1'];
  115. $departments = [
  116. 'Закупок' => $purchaseDepartment,
  117. 'Продаж' => $sellingDepartment,
  118. 'Рекламы' => $advertisementDepartment,
  119. 'Логистики' => $logisticsDepartment
  120. ];
  121. $total = [
  122. 'employees' => 0,
  123. 'salary' => 0,
  124. 'coffee' => 0,
  125. 'pages' => 0,
  126. 'tugrPerPage' => 0
  127. ];
  128. $avrg = [
  129. 'employees' => 0,
  130. 'salary' => 0,
  131. 'coffee' => 0,
  132. 'pages' => 0,
  133. 'tugrPerPage' => 0
  134. ];
  135. //Вывод
  136. foreach($departments as $name => $composition) {
  137. $composition = new Vector($composition);
  138. $tugrPerPage = round($composition->salary / $composition->pages, 2);
  139. $total['employees'] += $composition->employees;
  140. $total['salary'] += $composition->salary;
  141. $total['coffee'] += $composition->salary;
  142. $total['pages'] += $composition->pages;
  143. $total['tugrPerPage'] += $tugrPerPage;
  144. echo "\nДепартамент {$name}\n---------------------------\n";
  145. echo "Сотрудников: {$composition->employees}\n";
  146. echo "Тугриков: {$composition->salary}\n";
  147. echo "Кофе: {$composition->coffee}\n";
  148. echo "Страниц: {$composition->pages}\n";
  149. echo "Тугриков на страницу: {$tugrPerPage}\n";
  150. }
  151. $avrg['employees'] = round($total['employees']/count($departments), 2);
  152. $avrg['salary'] = round($total['salary']/count($departments),2);
  153. $avrg['coffee'] = round($total['coffee']/count($departments),2);
  154. $avrg['pages'] = round($total['pages']/count($departments),2);
  155. $avrg['tugrPerPage'] = round($total['tugrPerPage']/count($departments),2);
  156.  
  157. echo "\nВсего\n---------------------------\n";
  158. echo "Сотрудников: {$total['employees']}\n";
  159. echo "Тугриков: {$total['salary']}\n";
  160. echo "Кофе: {$total['coffee']}\n";
  161. echo "Страниц: {$total['pages']}\n";
  162. echo "Тугриков на страницу: {$total['tugrPerPage']}\n";
  163.  
  164. echo "\nСреднее\n---------------------------\n";
  165. echo "Сотрудников: {$avrg['employees']}\n";
  166. echo "Тугриков: {$avrg['salary']}\n";
  167. echo "Кофе: {$avrg['coffee']}\n";
  168. echo "Страниц: {$avrg['pages']}\n";
  169. echo "Тугриков на страницу: {$avrg['tugrPerPage']}\n";
  170.  
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Департамент Закупок
---------------------------
Сотрудников: 15
Тугриков: 7750
Кофе: 340
Страниц: 2600
Тугриков на страницу: 2.98

Департамент Продаж
---------------------------
Сотрудников: 24
Тугриков: 12500
Кофе: 695
Страниц: 3465
Тугриков на страницу: 3.61

Департамент Рекламы
---------------------------
Сотрудников: 36
Тугриков: 15900
Кофе: 570
Страниц: 5500
Тугриков на страницу: 2.89

Департамент Логистики
---------------------------
Сотрудников: 24
Тугриков: 10425
Кофе: 430
Страниц: 3800
Тугриков на страницу: 2.74

Всего
---------------------------
Сотрудников: 99
Тугриков: 46575
Кофе: 46575
Страниц: 15365
Тугриков на страницу: 12.22

Среднее
---------------------------
Сотрудников: 24.75
Тугриков: 11643.75
Кофе: 11643.75
Страниц: 3841.25
Тугриков на страницу: 3.06