<?php
class Vector
{
public $employees;
public $salary;
public $coffee;
public $pages;
private function countAll($qt, $rank, $salary, $coffee, $pages) {
switch($rank) {
case 1:
$salary *= $qt;
break;
case 2:
$salary += $salary*0.25;
$salary *= $qt;
break;
case 3:
$salary += $salary*0.5;
$salary *= $qt;
break;
case 'leader':
$salary += $salary*0.5;
$coffee *= 2;
$pages = 0;
}
$coffee *= $qt;
$pages *= $qt;
$results = [
"employees" => $qt,
"salary" => $salary,
"coffee" => $coffee,
"pages" => $pages
];
return $results;
}
private function definePost($qt, $post, $rank) { //Определяет должность
switch($post) {
case 'ме': //Менеджер
$salary = 500;
$coffee = 20;
$pages = 200;
$results = $this->countAll($qt, $rank, $salary, $coffee, $pages);
return $results;
case 'ма': //Маркетолог
$salary = 400;
$coffee = 15;
$pages = 150;
$results = $this->countAll($qt, $rank, $salary, $coffee, $pages);
return $results;
case 'ин': //Инженер
$salary = 200;
$coffee = 5;
$pages = 50;
$results = $this->countAll($qt, $rank, $salary, $coffee, $pages);
return $results;
case 'ан': //Аналитик
$salary = 800;
$coffee = 50;
$pages = 5;
$results = $this->countAll($qt, $rank, $salary, $coffee, $pages);
return $results;
}
}
private function splitQtPostRank($qtPostRank) {
$qt = preg_split('/х?ме|ма|ин|ан/u', $qtPostRank); if($qt[0] == "") {
$qt[0] = 1;
}
$rank = $qt[1]; //Ранг
$qt = $qt[0]; //Кол-во
$pattern = ["/[0-9]/u", "/х/u"];
$post = preg_filter($pattern, "",$qtPostRank); //Должность
$qtPostRank = ["qt" => $qt, "post" => $post, "rank" => $rank];
return $qtPostRank;
}
public function __construct($department) {
$employeesTotal = 0;
$salaryTotal = 0;
$coffeeTotal = 0;
$pagesTotal = 0;
$results = [];
$i = 0;
foreach($department as $qtPostRank) {
if(!preg_match('/([0-9]+)?+х?ме|ма|ин|ан[1-3]/u', $qtPostRank)) { //Проверка на соответствие шаблону die("Указанный параметр - неверный"); }
$qtPostRank = $this->splitQtPostRank($qtPostRank);
$qt = $qtPostRank["qt"];
$post = $qtPostRank["post"];
$rank = $qtPostRank["rank"];
$i++;
if($i == count($department)-1) { //проверка на руководителя $rank = 'leader';
}
$results = $this->definePost($qt, $post, $rank);
$employeesTotal += $results["employees"];
$salaryTotal += $results["salary"];
$coffeeTotal += $results["coffee"];
$pagesTotal += $results["pages"];
}
$this->employees = $employeesTotal;
$this->salary = $salaryTotal;
$this->coffee = $coffeeTotal;
$this->pages = $pagesTotal;
}
}
//Предполагается, что последний элемент массива всегда руководитель департамента,
//Департамент не может существовать без руководителя
$purchaseDepartment = ['9хме1', '3хме2', '2хме3', 'ме2'];
$sellingDepartment = ['12хме1','6хма1','3хан1','2хан2','ма2'];
$advertisementDepartment = ['15хма1', '10хма2', '8хме1', '2хин1', 'ма3'];
$logisticsDepartment = ['13хме1','5хме2','5хин1','ме1'];
$departments = [
'Закупок' => $purchaseDepartment,
'Продаж' => $sellingDepartment,
'Рекламы' => $advertisementDepartment,
'Логистики' => $logisticsDepartment
];
$total = [
'employees' => 0,
'salary' => 0,
'coffee' => 0,
'pages' => 0,
'tugrPerPage' => 0
];
$avrg = [
'employees' => 0,
'salary' => 0,
'coffee' => 0,
'pages' => 0,
'tugrPerPage' => 0
];
//Вывод
foreach($departments as $name => $composition) {
$composition = new Vector($composition);
$tugrPerPage = round($composition->salary / $composition->pages, 2); $total['employees'] += $composition->employees;
$total['salary'] += $composition->salary;
$total['coffee'] += $composition->salary;
$total['pages'] += $composition->pages;
$total['tugrPerPage'] += $tugrPerPage;
echo "\nДепартамент {$name}\n---------------------------\n";
echo "Сотрудников: {$composition->employees}\n";
echo "Тугриков: {$composition->salary}\n";
echo "Кофе: {$composition->coffee}\n";
echo "Страниц: {$composition->pages}\n";
echo "Тугриков на страницу: {$tugrPerPage}\n";
}
$avrg['employees'] = round($total['employees']/count($departments), 2); $avrg['salary'] = round($total['salary']/count($departments),2); $avrg['coffee'] = round($total['coffee']/count($departments),2); $avrg['pages'] = round($total['pages']/count($departments),2); $avrg['tugrPerPage'] = round($total['tugrPerPage']/count($departments),2);
echo "\nВсего\n---------------------------\n";
echo "Сотрудников: {$total['employees']}\n";
echo "Тугриков: {$total['salary']}\n";
echo "Кофе: {$total['coffee']}\n";
echo "Страниц: {$total['pages']}\n";
echo "Тугриков на страницу: {$total['tugrPerPage']}\n";
echo "\nСреднее\n---------------------------\n";
echo "Сотрудников: {$avrg['employees']}\n";
echo "Тугриков: {$avrg['salary']}\n";
echo "Кофе: {$avrg['coffee']}\n";
echo "Страниц: {$avrg['pages']}\n";
echo "Тугриков на страницу: {$avrg['tugrPerPage']}\n";
PD9waHAKCmNsYXNzIFZlY3Rvcgp7CiAgICBwdWJsaWMgJGVtcGxveWVlczsKICAgIHB1YmxpYyAkc2FsYXJ5OwogICAgcHVibGljICRjb2ZmZWU7CiAgICBwdWJsaWMgJHBhZ2VzOwogICAgCiAgICBwcml2YXRlIGZ1bmN0aW9uIGNvdW50QWxsKCRxdCwgJHJhbmssICRzYWxhcnksICRjb2ZmZWUsICRwYWdlcykgewogICAgICAgIHN3aXRjaCgkcmFuaykgewogICAgICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgICAgICAkc2FsYXJ5ICo9ICRxdDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDI6CiAgICAgICAgICAgICAgICAkc2FsYXJ5ICs9ICRzYWxhcnkqMC4yNTsKICAgICAgICAgICAgICAgICRzYWxhcnkgKj0gJHF0OwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMzoKICAgICAgICAgICAgICAgICRzYWxhcnkgKz0gJHNhbGFyeSowLjU7CiAgICAgICAgICAgICAgICAkc2FsYXJ5ICo9ICRxdDsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlICdsZWFkZXInOgogICAgICAgICAgICAgICAgJHNhbGFyeSArPSAkc2FsYXJ5KjAuNTsKICAgICAgICAgICAgICAgICRjb2ZmZWUgKj0gMjsKICAgICAgICAgICAgICAgICRwYWdlcyA9IDA7CiAgICAgICAgfQogICAgICAgICRjb2ZmZWUgKj0gJHF0OwogICAgICAgICRwYWdlcyAqPSAkcXQ7CiAgICAgICAgJHJlc3VsdHMgPSBbCiAgICAgICAgICAgICJlbXBsb3llZXMiID0+ICRxdCwKICAgICAgICAgICAgInNhbGFyeSIgPT4gJHNhbGFyeSwKICAgICAgICAgICAgImNvZmZlZSIgPT4gJGNvZmZlZSwKICAgICAgICAgICAgInBhZ2VzIiA9PiAkcGFnZXMKICAgICAgICBdOwogICAgICAgIHJldHVybiAkcmVzdWx0czsKICAgIH0KICAgIHByaXZhdGUgZnVuY3Rpb24gZGVmaW5lUG9zdCgkcXQsICRwb3N0LCAkcmFuaykgeyAvL9Ce0L/RgNC10LTQtdC70Y/QtdGCINC00L7Qu9C20L3QvtGB0YLRjAogICAgICAgIHN3aXRjaCgkcG9zdCkgewogICAgICAgICAgICBjYXNlICfQvNC1JzogLy/QnNC10L3QtdC00LbQtdGACiAgICAgICAgICAgICAgICAkc2FsYXJ5ID0gNTAwOwogICAgICAgICAgICAgICAgJGNvZmZlZSA9IDIwOwogICAgICAgICAgICAgICAgJHBhZ2VzID0gMjAwOwogICAgICAgICAgICAgICAgJHJlc3VsdHMgPSAkdGhpcy0+Y291bnRBbGwoJHF0LCAkcmFuaywgJHNhbGFyeSwgJGNvZmZlZSwgJHBhZ2VzKTsKICAgICAgICAgICAgICAgIHJldHVybiAkcmVzdWx0czsKICAgICAgICAgICAgY2FzZSAn0LzQsCc6IC8v0JzQsNGA0LrQtdGC0L7Qu9C+0LMKICAgICAgICAgICAgICAgICRzYWxhcnkgPSA0MDA7CiAgICAgICAgICAgICAgICAkY29mZmVlID0gMTU7CiAgICAgICAgICAgICAgICAkcGFnZXMgPSAxNTA7CiAgICAgICAgICAgICAgICAkcmVzdWx0cyA9ICR0aGlzLT5jb3VudEFsbCgkcXQsICRyYW5rLCAkc2FsYXJ5LCAkY29mZmVlLCAkcGFnZXMpOwogICAgICAgICAgICAgICAgcmV0dXJuICRyZXN1bHRzOyAKICAgICAgICAgICAgY2FzZSAn0LjQvSc6IC8v0JjQvdC20LXQvdC10YAKICAgICAgICAgICAgICAgICRzYWxhcnkgPSAyMDA7CiAgICAgICAgICAgICAgICAkY29mZmVlID0gNTsKICAgICAgICAgICAgICAgICRwYWdlcyA9IDUwOwogICAgICAgICAgICAgICAgJHJlc3VsdHMgPSAkdGhpcy0+Y291bnRBbGwoJHF0LCAkcmFuaywgJHNhbGFyeSwgJGNvZmZlZSwgJHBhZ2VzKTsKICAgICAgICAgICAgICAgIHJldHVybiAkcmVzdWx0czsgCiAgICAgICAgICAgIGNhc2UgJ9Cw0L0nOiAvL9CQ0L3QsNC70LjRgtC40LoKICAgICAgICAgICAgICAgICRzYWxhcnkgPSA4MDA7CiAgICAgICAgICAgICAgICAkY29mZmVlID0gNTA7CiAgICAgICAgICAgICAgICAkcGFnZXMgPSA1OwogICAgICAgICAgICAgICAgJHJlc3VsdHMgPSAkdGhpcy0+Y291bnRBbGwoJHF0LCAkcmFuaywgJHNhbGFyeSwgJGNvZmZlZSwgJHBhZ2VzKTsKICAgICAgICAgICAgICAgIHJldHVybiAkcmVzdWx0czsKICAgICAgICB9IAogICAgfQogICAgcHJpdmF0ZSBmdW5jdGlvbiBzcGxpdFF0UG9zdFJhbmsoJHF0UG9zdFJhbmspIHsKICAgICAgICAkcXQgPSBwcmVnX3NwbGl0KCcv0YU/0LzQtXzQvNCwfNC40L180LDQvS91JywgJHF0UG9zdFJhbmspOwogICAgICAgIGlmKCRxdFswXSA9PSAiIikgewogICAgICAgICAgICAkcXRbMF0gPSAxOwogICAgICAgIH0KICAgICAgICAkcmFuayA9ICRxdFsxXTsgLy/QoNCw0L3QswogICAgICAgICRxdCA9ICRxdFswXTsgLy/QmtC+0Lst0LLQvgogICAgICAgICRwYXR0ZXJuID0gWyIvWzAtOV0vdSIsICIv0YUvdSJdOwogICAgICAgICRwb3N0ID0gcHJlZ19maWx0ZXIoJHBhdHRlcm4sICIiLCRxdFBvc3RSYW5rKTsgLy/QlNC+0LvQttC90L7RgdGC0YwKICAgICAgICAkcXRQb3N0UmFuayA9IFsicXQiID0+ICRxdCwgInBvc3QiID0+ICRwb3N0LCAicmFuayIgPT4gJHJhbmtdOwogICAgICAgIHJldHVybiAkcXRQb3N0UmFuazsKICAgIH0KICAgIHB1YmxpYyBmdW5jdGlvbiBfX2NvbnN0cnVjdCgkZGVwYXJ0bWVudCkgewogICAgICAgICRlbXBsb3llZXNUb3RhbCA9IDA7CiAgICAgICAgJHNhbGFyeVRvdGFsID0gMDsKICAgICAgICAkY29mZmVlVG90YWwgPSAwOwogICAgICAgICRwYWdlc1RvdGFsID0gMDsKICAgICAgICAkcmVzdWx0cyA9IFtdOwogICAgICAgICRpID0gMDsKICAgICAgICBmb3JlYWNoKCRkZXBhcnRtZW50IGFzICRxdFBvc3RSYW5rKSB7CiAgICAgICAgICAgIGlmKCFwcmVnX21hdGNoKCcvKFswLTldKyk/K9GFP9C80LV80LzQsHzQuNC9fNCw0L1bMS0zXS91JywgJHF0UG9zdFJhbmspKSB7IC8v0J/RgNC+0LLQtdGA0LrQsCDQvdCwINGB0L7QvtGC0LLQtdGC0YHRgtCy0LjQtSDRiNCw0LHQu9C+0L3RgwogICAgICAgICAgICAgICAgZGllKCLQo9C60LDQt9Cw0L3QvdGL0Lkg0L/QsNGA0LDQvNC10YLRgCAtINC90LXQstC10YDQvdGL0LkiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICAkcXRQb3N0UmFuayA9ICR0aGlzLT5zcGxpdFF0UG9zdFJhbmsoJHF0UG9zdFJhbmspOwogICAgICAgICAgICAkcXQgPSAkcXRQb3N0UmFua1sicXQiXTsKICAgICAgICAgICAgJHBvc3QgPSAkcXRQb3N0UmFua1sicG9zdCJdOwogICAgICAgICAgICAkcmFuayA9ICRxdFBvc3RSYW5rWyJyYW5rIl07CiAgICAgICAgICAgICRpKys7CiAgICAgICAgICAgIGlmKCRpID09IGNvdW50K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