@ 2018-01-14T00:12:57Z <?php
error_reporting(-1);
abstract class AbstractWorker
{
private $rank;
private $isBoss;
private $salary;
private $coffee;
abstract public function getBasicPages(): int;
public function __construct(int $rank, bool $isBoss, int $salary, int $coffee)
{
$this->rank = $rank;
$this->isBoss = $isBoss;
$this->coffee = $coffee;
$this->salary = $salary;
}
public function getRank(): int
{
return $this->rank;
}
public function setRank(int $rank): void
{
$this->rank = $rank;
}
public function getBoss(): bool
{
return $this->isBoss;
}
public function setBoss(bool $isBoss): void
{
$this->isBoss = $isBoss;
}
public function getSalary(): float
{
$modifiedSalary = $this->salary;
if ($this->rank == 2){
$modifiedSalary *= 1.25;
} elseif ($this->rank == 3){
$modifiedSalary *= 1.5;
}
if ($this->isBoss){
$modifiedSalary *= 1.5;
}
return $modifiedSalary;
}
public function getCoffee(): int
{
$modifiedCoffee = $this->coffee;
if ($this->isBoss){
$modifiedCoffee *= 2;
}
return $modifiedCoffee;
}
public function getPages(): int
{
$pages = $this->getBasicPages();
if ($this->isBoss){
$pages = 0;
}
return $pages;
}
public function setSalary(float $salary): void
{
$this->salary = $salary;
}
public function setCoffee(int $coffee): void
{
$this->coffee = $coffee;
}
}
class Manager extends AbstractWorker
{
public function getBasicPages(): int
{
return 200;
}
}
class Marketer extends AbstractWorker
{
public function getBasicPages(): int
{
return 150;
}
}
class Engineer extends AbstractWorker
{
public function getBasicPages(): int
{
return 50;
}
}
class Analyst extends AbstractWorker
{
public function getBasicPages(): int
{
return 5;
}
}
class Department
{
private $name;
private $workers = array();
public function __construct(string $name)
{
$this->name = $name;
}
public function getName(): string
{
return $this->name;
}
public function addWorker(AbstractWorker $worker): void
{
$this->workers[] = $worker;
}
public function getNumberWorkers(): int
{
return count($this->workers);
}
public function getDepartmentSalary(): float
{
$totalSalary = 0;
foreach ($this->workers as $worker) {
$totalSalary += $worker->getSalary();
}
return $totalSalary;
}
public function getDepartmentCoffee(): int
{
$totalCoffee = 0;
foreach ($this->workers as $worker) {
$totalCoffee += $worker->getCoffee();
}
return $totalCoffee;
}
public function getDepartmentPages(): int
{
$totalPages = 0;
foreach ($this->workers as $worker) {
$totalPages += $worker->getPages();
}
return $totalPages;
}
public function getDepartmentName(): string
{
return $this->name;
}
public function getWorkers(): array
{
return $this->workers;
}
public function getWorker(int $key): AbstractWorker
{
return $this->workers[$key];
}
public function deleteWorker(int $key): void
{
unset($this->workers[$key]);
}
public function selectWorkers(string $profession): array
{
$workersOfCertainProfession = array();
foreach ($this->workers as $worker) {
if (get_class($worker) == $profession && $worker->getBoss() == FALSE){
$workersOfCertainProfession[] = $worker;
}
}
return $workersOfCertainProfession;
}
public function changeBoss(int $oldBoss, int $newBoss)
{
$this->workers[$oldBoss]->setBoss(FALSE);
$this->workers[$newBoss]->setBoss(TRUE);
}
}
class Company
{
private $departments = array();
public function addDepartment(Department $department): void
{
$this->departments[] = $department;
}
public function getDepartments(): array
{
return $this->departments;
}
public function getDepartmentCount(): int
{
return count($this->departments);
}
}
class HiringWorkers
{
public function addWorkersToDepartment(Department $department, string $profession, int $count, int $rank, bool $isBoss, float $salary, int $coffee): void
{
if ($profession == Manager::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Manager($rank, $isBoss, $salary, $coffee));
}
} elseif ($profession == Marketer::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Marketer($rank, $isBoss, $salary, $coffee));
}
} elseif ($profession == Engineer::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Engineer ($rank, $isBoss, $salary, $coffee));
}
} elseif ($profession == Analyst::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Analyst ($rank, $isBoss, $salary, $coffee));
}
} else {
throw new Exception("Введено ошибочное название профессии");
}
}
}
class Tabel
{
public function printTabel(Company $company): void
{
$this->printRow("Департамент", "сотр.", "тугр.", "кофе", "стр", "тугр./стр.");
echo "\n";
foreach ($company->getDepartments() as $department) {
$this->printRow($department->getDepartmentName(), $department->getNumberWorkers(), $department->getDepartmentSalary(), $department->getDepartmentCoffee(), $department->getDepartmentPages(), round($department->getDepartmentSalary() / $department->getDepartmentPages(), 1));
}
echo "\n";
$count = 0;
$salary = 0;
$coffee = 0;
$pages = 0;
$salaryDividePages = 0;
foreach ($company->getDepartments() as $department) {
$count += $department->getNumberWorkers();
$salary += $department->getDepartmentSalary();
$coffee += $department->getDepartmentCoffee();
$pages += $department->getDepartmentPages();
$salaryDividePages += round($salary / $pages, 1);
}
$this->printRow("Всего", $count, $salary, $coffee, $pages, $salaryDividePages);
$this->printRow("Среднее", round($count / $company->getDepartmentCount(), 1), round($salary / $company->getDepartmentCount(), 1), round($coffee / $company->getDepartmentCount(), 1), round($pages / $company->getDepartmentCount(), 1), round($salaryDividePages / $company->getDepartmentCount(), 1));
echo "\n";
}
private function padLeft($value, $columnLength): void
{
echo $value;
echo str_repeat(" ", $columnLength - mb_strlen($value));
}
private function printRow(string $name, $count, $salary, $coffee, $pages, $salaryDividePages): void
{
$col1 = 15;
$col2 = 10;
$col3 = 10;
$col4 = 8;
$col5 = 8;
$col6 = 15;
echo $this->padLeft($name, $col1) . $this->padLeft($count, $col2) . $this->padLeft($salary, $col3) . $this->padLeft($coffee, $col4) . $this->padLeft($pages, $col5) . $this->padLeft($salaryDividePages, $col6) . "\n";
}
}
class AnticrisisService
{
public function cutEngineers(Company $company): void
{
foreach ($company->getDepartments() as $department) {
$workersOfCertainProfession = array();
$workersOfCertainProfession = $department->selectWorkers("Engineer");
if (count($workersOfCertainProfession) == 0){
continue;
}
do {
$numberOfPermutations = 0;
for ($i = 0; $i < count($workersOfCertainProfession) - 2; $i++){
if ($workersOfCertainProfession[$i]->getRank() == $workersOfCertainProfession[$i+1]){
$buf = $workersOfCertainProfession[$i];
$workersOfCertainProfession[$i] = $workersOfCertainProfession[$i+1];
$workersOfCertainProfession[$i+1] = $buf;
$numberOfPermutations++;
}
}
} while ($numberOfPermutations != 0);
$workersOfCertainProfession = array_slice($workersOfCertainProfession, 0, ceil(count($workersOfCertainProfession) / 2.5));
var_dump($workersOfCertainProfession);
foreach ($department->getWorkers() as $key => $worker) {
if ($worker == $workersOfCertainProfession[0]){
$department->deleteWorker($key);
unset($workersOfCertainProfession[0]);
sort($workersOfCertainProfession);
}
}
}
}
public function changeDataAnalytics(Company $company): void
{
foreach ($company->getDepartments() as $department) {
$countOfBasicAnalyst = 0;
$keyOfBestAnalyst = 0;
$rankOfBestAnalyst = 0;
$keyOfWorker = -1;
foreach ($department->getWorkers() as $worker) {
$keyOfWorker++;
if ($worker instanceof Analyst){
$worker->setSalary(1100);
$worker->setCoffee(75);
if ($worker->getBoss() == FALSE){
$countOfBasicAnalyst++;
if ($worker->getRank() > $rankOfBestAnalyst){
$rankOfBestAnalyst = $worker->getRank();
$keyOfBestAnalyst = $keyOfWorker;
}
}
}
}
if (!($department->getWorker($department->getNumberWorkers()-1) instanceof Analyst) && $countOfBasicAnalyst > 0){
$department->changeBoss($department->getNumberWorkers()-1, $keyOfBestAnalyst);
}
}
}
public function increaseManagers(Company $company): void
{
foreach ($company->getDepartments() as $department) {
$manager1RangCount = 0;
$manager2RangCount = 0;
foreach ($department->getWorkers() as $worker) {
if ($worker instanceof Manager && ($worker->getRank() == 1)){
$manager1RangCount++;
} elseif ($worker instanceof Manager && ($worker->getRank() == 2)){
$manager2RangCount++;
}
}
$manager1RangCount = ceil($manager1RangCount / 2);
$manager2RangCount = ceil($manager2RangCount / 2);
foreach ($department->getWorkers() as $worker) {
if($manager1RangCount + $manager2RangCount == 0){
break;
}
if ($worker instanceof Manager && $worker->getRank() == 1 && $manager1RangCount > 0){
$worker->setRank($worker->getRank()+1);
$manager1RangCount--;
} elseif ($worker instanceof Manager && $worker->getRank() == 2 && $manager2RangCount > 0) {
$worker->setRank($worker->getRank()+1);
$manager2RangCount--;
}
}
}
}
}
$vektor = new Company;
$tabel = new Tabel;
$hiringWorkers = new HiringWorkers;
$departmentOfProcurement = new Department("Закупок");
$hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 9, 1, FALSE, 500, 20);
$hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 3, 2, FALSE, 500, 20);
$hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 2, 3, FALSE, 500, 20);
$hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Marketer", 2, 1, FALSE, 400, 15);
$hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 1, 2, TRUE, 500, 20);
$departmentOfSales = new Department("Продаж");
$hiringWorkers->addWorkersToDepartment($departmentOfSales, "Manager", 12, 1, FALSE, 500, 20);
$hiringWorkers->addWorkersToDepartment($departmentOfSales, "Marketer", 6, 1, FALSE, 400, 15);
$hiringWorkers->addWorkersToDepartment($departmentOfSales, "Analyst", 3, 1, FALSE, 800, 50);
$hiringWorkers->addWorkersToDepartment($departmentOfSales, "Analyst", 2, 2, FALSE, 800, 50);
$hiringWorkers->addWorkersToDepartment($departmentOfSales, "Marketer", 1, 2, TRUE, 400, 15);
$departmentOfAdvertising = new Department("Рекламы");
$hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Marketer", 15, 1, FALSE, 400, 15);
$hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Marketer", 10, 2, FALSE, 400, 15);
$hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Manager", 8, 1, FALSE, 500, 20);
$hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Engineer", 2, 1, FALSE, 200, 5);
$hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Marketer", 1, 3, TRUE, 400, 15);
$departmentOfLogistics = new Department("Логистики");
$hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Manager", 13, 1, FALSE, 500, 20);
$hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Manager", 5, 2, FALSE, 500, 20);
$hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Engineer", 5, 1, FALSE, 200, 5);
$hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Manager", 1, 1, TRUE, 500, 20);
$vektor->addDepartment($departmentOfProcurement);
$vektor->addDepartment($departmentOfSales);
$vektor->addDepartment($departmentOfAdvertising);
$vektor->addDepartment($departmentOfLogistics);
$anticrisisService = new AnticrisisService;
$anticrisisService->changeDataAnalytics($vektor);
$tabel->printTabel($vektor);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.6 0.017 0.007 18.30 8.3.5 0.008 0.008 16.50 8.3.4 0.000 0.015 18.88 8.3.3 0.015 0.000 18.87 8.3.2 0.003 0.006 19.04 8.3.1 0.009 0.000 23.66 8.3.0 0.009 0.000 19.49 8.2.18 0.012 0.003 18.29 8.2.17 0.016 0.006 22.96 8.2.16 0.010 0.007 19.21 8.2.15 0.005 0.003 24.18 8.2.14 0.009 0.000 24.66 8.2.13 0.005 0.003 26.16 8.2.12 0.005 0.003 21.08 8.2.11 0.006 0.006 20.95 8.2.10 0.010 0.003 18.16 8.2.9 0.000 0.008 19.42 8.2.8 0.007 0.003 19.32 8.2.7 0.007 0.003 18.28 8.2.6 0.004 0.004 18.18 8.2.5 0.006 0.004 18.53 8.2.4 0.004 0.004 20.92 8.2.3 0.000 0.009 19.47 8.2.2 0.004 0.004 18.46 8.2.1 0.000 0.009 18.46 8.2.0 0.000 0.009 18.64 8.1.28 0.010 0.006 25.92 8.1.27 0.004 0.007 20.16 8.1.26 0.003 0.007 26.35 8.1.25 0.003 0.006 28.09 8.1.24 0.007 0.004 21.18 8.1.23 0.009 0.003 20.56 8.1.22 0.003 0.006 18.02 8.1.21 0.004 0.004 18.77 8.1.20 0.008 0.000 17.73 8.1.19 0.004 0.004 17.60 8.1.18 0.008 0.000 18.10 8.1.17 0.004 0.004 18.87 8.1.16 0.009 0.000 19.13 8.1.15 0.004 0.004 19.16 8.1.14 0.005 0.003 19.28 8.1.13 0.006 0.003 19.29 8.1.12 0.003 0.006 17.75 8.1.11 0.003 0.006 17.69 8.1.10 0.000 0.008 17.63 8.1.9 0.004 0.004 17.70 8.1.8 0.000 0.008 17.74 8.1.7 0.004 0.004 17.78 8.1.6 0.006 0.003 17.88 8.1.5 0.000 0.008 17.81 8.1.4 0.003 0.006 17.75 8.1.3 0.004 0.004 17.89 8.1.2 0.004 0.004 17.93 8.1.1 0.006 0.003 17.80 8.1.0 0.000 0.009 17.83 8.0.30 0.007 0.004 18.77 8.0.29 0.009 0.000 17.25 8.0.28 0.004 0.004 18.77 8.0.27 0.010 0.002 17.58 8.0.26 0.007 0.000 17.60 8.0.25 0.004 0.004 17.41 8.0.24 0.007 0.004 17.32 8.0.23 0.004 0.004 17.23 8.0.22 0.006 0.003 17.26 8.0.21 0.007 0.000 17.27 8.0.20 0.007 0.000 17.37 8.0.19 0.004 0.004 17.38 8.0.18 0.002 0.005 17.32 8.0.17 0.009 0.000 17.21 8.0.16 0.003 0.006 17.35 8.0.15 0.000 0.008 17.20 8.0.14 0.003 0.005 17.25 8.0.13 0.003 0.003 13.72 8.0.12 0.003 0.005 17.26 8.0.11 0.009 0.000 17.23 8.0.10 0.000 0.008 17.36 8.0.9 0.003 0.006 17.19 8.0.8 0.015 0.003 17.31 8.0.7 0.004 0.004 17.11 8.0.6 0.004 0.004 17.17 8.0.5 0.003 0.005 17.20 8.0.3 0.014 0.008 17.30 8.0.2 0.015 0.010 17.48 8.0.1 0.003 0.005 17.38 8.0.0 0.006 0.014 17.12 7.4.33 0.003 0.003 16.77 7.4.32 0.000 0.007 16.79 7.4.30 0.000 0.008 16.80 7.4.29 0.008 0.000 16.81 7.4.28 0.000 0.009 16.78 7.4.27 0.000 0.007 16.86 7.4.26 0.004 0.004 16.77 7.4.25 0.003 0.005 16.61 7.4.24 0.004 0.004 16.75 7.4.23 0.004 0.004 16.71 7.4.22 0.006 0.003 16.61 7.4.21 0.017 0.000 16.75 7.4.20 0.003 0.006 16.80 7.4.16 0.010 0.010 16.84 7.4.15 0.007 0.015 17.40 7.4.14 0.018 0.007 17.86 7.4.13 0.014 0.006 16.82 7.4.12 0.011 0.013 16.83 7.4.11 0.007 0.011 16.84 7.4.10 0.009 0.018 16.79 7.4.9 0.018 0.004 16.90 7.4.8 0.011 0.008 19.39 7.4.7 0.014 0.006 16.95 7.4.6 0.007 0.010 16.75 7.4.5 0.012 0.006 16.63 7.4.4 0.007 0.014 16.67 7.4.0 0.007 0.011 15.19 7.3.33 0.006 0.000 13.61 7.3.32 0.003 0.003 13.46 7.3.31 0.008 0.000 16.70 7.3.30 0.004 0.004 16.70 7.3.29 0.007 0.014 16.61 7.3.28 0.011 0.013 16.63 7.3.27 0.003 0.016 17.40 7.3.26 0.018 0.006 16.63 7.3.25 0.012 0.008 16.75 7.3.24 0.009 0.010 16.72 7.3.23 0.011 0.008 16.64 7.3.21 0.011 0.007 16.67 7.3.20 0.015 0.009 16.64 7.3.19 0.004 0.014 16.78 7.3.18 0.016 0.003 16.52 7.3.17 0.014 0.006 16.63 7.3.16 0.008 0.016 16.79 7.3.12 0.013 0.003 15.16 7.3.11 0.012 0.008 15.39 7.3.10 0.003 0.009 14.93 7.3.9 0.003 0.012 15.31 7.3.8 0.007 0.004 15.45 7.3.7 0.008 0.009 15.20 7.3.6 0.004 0.011 14.97 7.3.5 0.006 0.009 15.09 7.3.4 0.009 0.006 14.99 7.3.3 0.006 0.010 15.18 7.3.2 0.004 0.014 16.73 7.3.1 0.010 0.000 16.75 7.3.0 0.008 0.004 16.70 7.2.33 0.006 0.019 16.83 7.2.32 0.003 0.016 16.73 7.2.31 0.006 0.014 16.89 7.2.30 0.011 0.008 16.89 7.2.29 0.014 0.010 16.93 7.2.25 0.016 0.003 15.11 7.2.24 0.004 0.018 15.29 7.2.23 0.004 0.012 15.31 7.2.22 0.003 0.012 15.33 7.2.21 0.000 0.016 15.42 7.2.20 0.010 0.003 15.19 7.2.19 0.000 0.014 14.95 7.2.18 0.000 0.014 15.47 7.2.17 0.000 0.013 15.33 7.2.6 0.006 0.012 16.84 7.2.5 0.006 0.009 16.88 7.2.1 0.027 0.015 18.40 7.2.0 0.014 0.018 18.20 7.1.33 0.009 0.006 15.78 7.1.32 0.004 0.012 15.79 7.1.31 0.007 0.007 15.78 7.1.30 0.006 0.006 15.70 7.1.29 0.010 0.003 15.86 7.1.28 0.006 0.009 15.66 7.1.27 0.012 0.006 15.78 7.1.26 0.004 0.008 15.93 7.1.20 0.006 0.006 15.97 7.1.13 0.024 0.007 16.85 7.1.12 0.017 0.010 16.94 7.1.11 0.021 0.006 16.56 7.1.10 0.016 0.012 16.54 7.1.9 0.033 0.007 16.27 7.1.8 0.017 0.013 16.45 7.1.7 0.017 0.014 15.28 7.1.6 0.035 0.017 33.40 7.1.5 0.020 0.024 33.38 7.1.4 0.029 0.016 33.03 7.1.3 0.039 0.020 32.83 7.1.2 0.027 0.017 33.02 7.1.1 0.016 0.013 14.90 7.1.0 0.061 0.014 15.22
preferences:dark mode live preview
65.62 ms | 400 KiB | 5 Q