fork download
  1. <?php
  2.  
  3.  
  4. class Worker
  5. {
  6. public function __construct($salary, $coffee, $reports, $a, $b, $c) //$a - 1 если 2 ранг, 0 если нет, $b - 1 (3 ранг), $c - 1 (если директор)
  7. {
  8. $salarySecond = $salary + $salary * 0.25 * $a;
  9. $salaryThird = $salarySecond + $salarySecond * 0.5 * $b;
  10. $salaryDir = $salaryThird + $salaryThird * 0.5 * $c;
  11. $coffeeDir = $coffee + $coffee * $c;
  12. $reportsDir = $reports * (1 - $c);
  13. $this->salary = $salaryDir;
  14. $this->coffee = $coffeeDir;
  15. $this->reports = $reportsDir;
  16. }
  17. }
  18. $me = array(
  19. 500,
  20. 20,
  21. 200
  22. );
  23. $ma = array(
  24. 400,
  25. 15,
  26. 150
  27. );
  28. $en = array(
  29. 200,
  30. 5,
  31. 50
  32. );
  33. $an = array(
  34. 800,
  35. 50,
  36. 5
  37. );
  38. function doWorkers($array, $x, $a, $b, $c)
  39. {
  40. $workers = array();
  41. for ($i = 1; $i <= $x; $i++) {
  42. list($k1, $k2, $k3) = $array;
  43. $worker = new Worker($k1, $k2, $k3, $a, $b, $c);
  44. $workers[] = $worker;
  45. }
  46. return $workers;
  47. }
  48. $depZakupok = array();
  49. $depZakupok[] = doWorkers($me, 9, 0, 0, 0);
  50. $depZakupok[] = doWorkers($me, 3, 1, 0, 0);
  51. $depZakupok[] = doWorkers($me, 2, 0, 1, 0);
  52. $depZakupok[] = doWorkers($ma, 2, 0, 0, 0);
  53. $depZakupok[] = doWorkers($ma, 1, 0, 0, 1);
  54. $depProdaj = array();
  55. $depProdaj[] = doWorkers($me, 12, 0, 0, 0);
  56. $depProdaj[] = doWorkers($ma, 6, 0, 0, 0);
  57. $depProdaj[] = doWorkers($an, 3, 0, 0, 0);
  58. $depProdaj[] = doWorkers($an, 2, 1, 0, 0);
  59. $depProdaj[] = doWorkers($ma, 1, 1, 0, 1);
  60. $depReklamy = array();
  61. $depReklamy[] = doWorkers($ma, 15, 0, 0, 0);
  62. $depReklamy[] = doWorkers($ma, 10, 1, 0, 0);
  63. $depReklamy[] = doWorkers($me, 8, 0, 0, 0);
  64. $depReklamy[] = doWorkers($en, 2, 0, 0, 0);
  65. $depReklamy[] = doWorkers($ma, 1, 0, 1, 1);
  66. $depLogist = array();
  67. $depLogist[] = doWorkers($me, 13, 0, 0, 0);
  68. $depLogist[] = doWorkers($me, 5, 1, 0, 0);
  69. $depLogist[] = doWorkers($en, 5, 0, 0, 0);
  70. $depLogist[] = doWorkers($me, 1, 0, 0, 0);
  71. $vektor = array(
  72. $depZakupok,
  73. $depProdaj,
  74. $depReklamy,
  75. $depLogist
  76. );
  77.  
  78. $countLogist = count($depLogist, 1) - count($depLogist);
  79. $countRek = count($depReklamy, 1) - count($depReklamy);
  80. $countProd = count($depProdaj, 1) - count($depProdaj);
  81. $countZak = count($depZakupok, 1) - count($depZakupok);
  82. $vektorCount = $countLogist + $countRek + $countProd + $countZak;
  83.  
  84.  
  85. function doTotalSalaryDep($array)
  86. {
  87. $summary = 0;
  88. foreach ($array as $group) {
  89. foreach ($group as $worker) {
  90. $summary += $worker->salary . "\n";
  91. }
  92. }
  93. return $summary;
  94. }
  95. $zakSalary = doTotalSalaryDep($depZakupok);
  96. $prodSalary = doTotalSalaryDep($depProdaj);
  97. $rekSalary = doTotalSalaryDep($depReklamy);
  98. $logSalary = doTotalSalaryDep($depLogist);
  99. $vektorSalary = $zakSalary + $prodSalary + $rekSalary + $logSalary;
  100.  
  101.  
  102. function doTotalReportsDep($array)
  103. {
  104. $summary = 0;
  105. foreach ($array as $group) {
  106. foreach ($group as $worker) {
  107. $summary += $worker->reports;
  108. }
  109. }
  110. return $summary;
  111. }
  112. $zakRep = doTotalReportsDep($depZakupok);
  113. $prodRep = doTotalReportsDep($depProdaj);
  114. $rekRep = doTotalReportsDep($depReklamy);
  115. $logRep = doTotalReportsDep($depLogist);
  116. $vektorRep = $zakRep + $prodRep + $rekRep + $logRep;
  117.  
  118. function doTotalCoffeeDep($array)
  119. {
  120. $summary = 0;
  121. foreach ($array as $group) {
  122. foreach ($group as $worker) {
  123. $summary += $worker->coffee;
  124. }
  125. }
  126. return $summary;
  127. }
  128. $zakCoffee = doTotalCoffeeDep($depZakupok);
  129. $prodCoffee = doTotalCoffeeDep($depProdaj);
  130. $rekCoffee = doTotalCoffeeDep($depReklamy);
  131. $logCoffee = doTotalCoffeeDep($depLogist);
  132. $vektorCoffee = $zakCoffee + $prodCoffee + $rekCoffee + $logCoffee;
  133.  
  134. $zakRepSal = $zakSalary / $zakRep;
  135. $prodRepSal = $prodSalary / $prodRep;
  136. $rekRepSal = $rekSalary / $rekRep;
  137. $logRepSal = $logSalary / $logRep;
  138. $vektorRepSal = $vektorSalary / $vektorRep;
  139.  
  140.  
  141. $col1 = 20;
  142. $col2 = 8;
  143.  
  144. function padRight($string, $arg)
  145. {
  146. $count = $arg - mb_strlen($string);
  147. if ($count <= 0) {
  148. return $string;
  149. }
  150. $space = str_repeat(' ', $count);
  151. return $string . $space;
  152. }
  153. function padLeft($string, $arg)
  154. {
  155. $count = $arg - mb_strlen($string);
  156. if ($count <= 0) {
  157. return $string;
  158. }
  159. $space = str_repeat(' ', $count);
  160. return $space . $string;
  161. }
  162. echo padRight('Департамент', $col1) . padLeft('сотр.', $col2) . padLeft('тугр', $col2) . padLeft('кофе', $col2) . padLeft('стр.', $col2) . padLeft('тугр./стр.', $col1) . "\n";
  163. echo str_repeat('-', $col1 * 2 + $col2 * 4 + 5) . "\n";
  164. echo padRight('Деп. Закупок', $col1) . padLeft("$countZak", $col2) . padLeft("$zakSalary", $col2) . padLeft("$zakCoffee", $col2) . padLeft("$zakRep", $col2) . padLeft(number_format($zakRepSal, 2), $col1) . "\n";
  165. echo padRight('Деп. Продаж', $col1) . padLeft("$countProd", $col2) . padLeft("$prodSalary", $col2) . padLeft("$prodCoffee", $col2) . padLeft("$prodRep", $col2) . padLeft(number_format($prodRepSal, 2), $col1) . "\n";
  166. echo padRight('Деп. Рекламы', $col1) . padLeft("$countRek", $col2) . padLeft("$rekSalary", $col2) . padLeft("$rekCoffee", $col2) . padLeft("$rekRep", $col2) . padLeft(number_format($rekRepSal, 2), $col1) . "\n";
  167. echo padRight('Деп. Логистики', $col1) . padLeft("$countLogist", $col2) . padLeft("$logSalary", $col2) . padLeft("$logCoffee", $col2) . padLeft("$logRep", $col2) . padLeft(number_format($logRepSal, 2), $col1) . "\n";
  168. echo str_repeat('-', $col1 * 2 + $col2 * 4 + 5) . "\n";
  169. echo padRight('ВСЕГО:', $col1) . padLeft("$vektorCount", $col2) . padLeft("$vektorSalary", $col2) . padLeft("$vektorCoffee", $col2) . padLeft("$vektorRep", $col2) . padLeft(number_format($vektorRepSal, 2), $col1) . "\n";
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Департамент            сотр.    тугр    кофе    стр.          тугр./стр.
-----------------------------------------------------------------------------
Деп. Закупок              17    9275     340    3100                2.99
Деп. Продаж               24   13550     610    3325                4.08
Деп. Рекламы              36   16300     575    5450                2.99
Деп. Логистики            24   11125     405    4050                2.75
-----------------------------------------------------------------------------
ВСЕГО:                   101   50250    1930   15925                3.16