@ 2017-11-19T10:37:18Z <?php
error_reporting(-1);
abstract class AbstractWorker
{
public $rank;
public $isBoss;
public function __construct(int $rank, int $isBoss)
{
$this->rank = $rank;
$this->isBoss = $isBoss;
}
public function getSalary(): float
{
$salary = $this->getBasicSalary();
if ($this->rank == 2){
$salary *= 1.25;
} elseif ($this->rank == 3){
$salary *= 1.5;
}
if ($this->isBoss == 1){
$salary *= 1.5;
}
return $salary;
}
public function getCoffee(): int
{
$coffee = $this->getBasicCoffee();
if ($this->isBoss == 1){
$coffee *= 2;
}
return $coffee;
}
public function getPages(): int
{
$pages = $this->getBasicPages();
if ($this->isBoss == 1){
$pages = 0;
}
return $pages;
}
abstract public function getBasicSalary(): int;
abstract public function getBasicCoffee(): int;
abstract public function getBasicPages(): int;
}
class Manager extends AbstractWorker
{
public function getBasicSalary(): int
{
return 500;
}
public function getBasicCoffee(): int
{
return 20;
}
public function getBasicPages(): int
{
return 200;
}
}
class Marketer extends AbstractWorker
{
public function getBasicSalary(): int
{
return 400;
}
public function getBasicCoffee(): int
{
return 15;
}
public function getBasicPages(): int
{
return 150;
}
}
class Engineer extends AbstractWorker
{
public function getBasicSalary(): int
{
return 200;
}
public function getBasicCoffee(): int
{
return 5;
}
public function getBasicPages(): int
{
return 50;
}
}
class Analyst extends AbstractWorker
{
public function getBasicSalary(): int
{
return 800;
}
public function getBasicCoffee(): int
{
return 50;
}
public function getBasicPages(): int
{
return 5;
}
}
class Department
{
private $name;
private $workers = array();
public function __construct(string $name)
{
$this->name = $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 $number): AbstractWorker
{
return $this->workers[$number];
}
public function deleteWorker(int $number): void
{
unset($this->workers[$number]);
}
public function sortWorkers(): void
{
sort($this->workers);
}
}
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);
}
public function __clone()
{
$cloneDepartment = array();
foreach ($this->departments as $department) {
$cloneDepartment[] = clone $department;
}
$this->departments = $cloneDepartment;
}
}
class HiringWorkers
{
public function addWorkersToDepartment(Department $department, string $profession, int $count, int $rank, int $isBoss): void
{
if ($profession == Manager::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Manager($rank, $isBoss));
}
} elseif ($profession == Marketer::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Marketer($rank, $isBoss));
}
} elseif ($profession == Engineer::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Engineer ($rank, $isBoss));
}
} elseif ($profession == Analyst::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Analyst ($rank, $isBoss));
}
}
}
}
class Tabel
{
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";
}
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));
}
}
class AnticrisisSolutions
{
public function cutEngineers(Company $basicCompany): void
{
echo "\n\nСокращение инженеров \n\n";
$company = clone $basicCompany;
foreach ($company->getDepartments() as $department) {
$countEngineers3Rank = 0;
$countEngineers2Rank = 0;
$countEngineers1Rank = 0;
foreach ($department->getWorkers() as $worker) {
if (get_class($worker) == Engineer::class && $worker->rank == 1){
$countEngineers1Rank++;
} elseif (get_class($worker) == Engineer::class && $worker->rank == 2){
$countEngineers2Rank++;
} elseif (get_class($worker) == Engineer::class && $worker->rank == 3){
$countEngineers3Rank++;
}
}
$engineerCount = $countEngineers1Rank + $countEngineers2Rank + $countEngineers3Rank;
if ($engineerCount == 0){
continue;
}
$numberOfAbbreviatedEngineers = ceil($engineerCount / 2.5);
for ($i = $numberOfAbbreviatedEngineers; $i > 0; $i--){
if ($countEngineers1Rank >= $numberOfAbbreviatedEngineers){
$countEngineers1Rank = $numberOfAbbreviatedEngineers;
$countEngineers2Rank = 0;
$countEngineers3Rank = 0;
} elseif ($countEngineers1Rank + $countEngineers2Rank >= $numberOfAbbreviatedEngineers){
$countEngineers2Rank = $numberOfAbbreviatedEngineers - $countEngineers1Rank;
$countEngineers3Rank = 0;
} else {
$countEngineers3Rank = $numberOfAbbreviatedEngineers - $countEngineers1Rank - $countEngineers2Rank;
}
}
$departmentCount = $department->getNumberWorkers();
for ($numberOfWorker = 0; $numberOfWorker < $departmentCount && $numberOfAbbreviatedEngineers != 0; $numberOfWorker++){
if (get_class($department->getWorker($numberOfWorker)) == Engineer::class && $department->getWorker($numberOfWorker)->isBoss == 0 && $countEngineers1Rank > 0){
$department->deleteWorker($numberOfWorker);
$numberOfAbbreviatedEngineers--;
$countEngineers1Rank --;
} elseif (get_class($department->getWorker($numberOfWorker)) == Engineer::class && $department->getWorker($numberOfWorker)->isBoss == 0 && $countEngineers2Rank > 0){
$department->deleteWorker($numberOfWorker);
$numberOfAbbreviatedEngineers--;
$countEngineers2Rank --;
} else {
$department->deleteWorker($numberOfWorker);
$numberOfAbbreviatedEngineers--;
$countEngineers3Rank --;
}
}
$department->sortWorkers();
}
$tabel = new Tabel;
$tabel->printTabel($company);
}
public function changeDataAnalytics()
{
}
public function increaseManagers(Company $basicCompany): void
{
echo "\n\nПовышение менеджеров \n\n";
$company = clone $basicCompany;
$manager1RangCount = 0;
$manager2RangCount = 0;
foreach ($company->getDepartments() as $department) {
$manager1RangCount++;
$manager2RangCount++;
foreach ($department->getWorkers() as $worker) {
if (get_class($worker) == Manager::class && ($worker->rank == 1)){
$manager1RangCount++;
} elseif (get_class($worker) == Manager::class && ($worker->rank == 2)){
$manager2RangCount++;
}
}
$manager1RangCount = ceil($manager1RangCount / 2);
$manager2RangCount = ceil($manager2RangCount / 2);
foreach ($department->getWorkers() as $worker) {
if($manager1RangCount + $manager2RangCount == 0){
break;
}
if (get_class($worker) == Manager::class && $worker->rank == 1 && $manager1RangCount > 0){
$worker->rank++;
$manager1RangCount--;
} elseif (get_class($worker) == Manager::class && $worker->rank == 2 && $manager2RangCount > 0) {
$worker->rank++;
$manager2RangCount--;
}
}
}
$tabel = new Tabel;
$tabel->printTabel($company);
}
}
$vektor = new Company;
$tabel = new Tabel;
$hiringWorkers = new HiringWorkers;
$departmentOfProcurement = new Department("Закупок");
$hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 9, 1, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 3, 2, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 2, 3, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Marketer", 2, 1, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfProcurement, "Manager", 1, 2, 1);
$departmentOfSales = new Department("Продаж");
$hiringWorkers->addWorkersToDepartment($departmentOfSales, "Manager", 12, 1, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfSales, "Marketer", 6, 1, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfSales, "Analyst", 3, 1, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfSales, "Analyst", 2, 2, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfSales, "Marketer", 1, 2, 1);
$departmentOfAdvertising = new Department("Рекламы");
$hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Marketer", 15, 1, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Marketer", 10, 2, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Manager", 8, 1, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Engineer", 2, 1, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfAdvertising, "Marketer", 1, 3, 1);
$departmentOfLogistics = new Department("Логистики");
$hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Manager", 13, 1, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Manager", 5, 2, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Engineer", 5, 1, 0);
$hiringWorkers->addWorkersToDepartment($departmentOfLogistics, "Manager", 1, 1, 1);
$vektor->addDepartment($departmentOfProcurement);
$vektor->addDepartment($departmentOfSales);
$vektor->addDepartment($departmentOfAdvertising);
$vektor->addDepartment($departmentOfLogistics);
$tabel->printTabel($vektor);
$anticrisisSolutions = new AnticrisisSolutions;
$anticrisisSolutions->cutEngineers($vektor);
$anticrisisSolutions->increaseManagers($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.7 0.010 0.010 16.88 8.3.6 0.017 0.003 17.00 8.3.5 0.014 0.012 16.67 8.3.4 0.007 0.010 18.82 8.3.3 0.007 0.014 19.01 8.3.2 0.000 0.012 20.62 8.3.1 0.003 0.013 23.65 8.3.0 0.004 0.012 23.78 8.2.19 0.010 0.013 17.00 8.2.18 0.003 0.020 18.52 8.2.17 0.013 0.007 22.96 8.2.16 0.016 0.006 19.11 8.2.15 0.009 0.000 24.18 8.2.14 0.004 0.004 24.66 8.2.13 0.009 0.006 22.24 8.2.12 0.009 0.006 26.35 8.2.11 0.005 0.005 22.39 8.2.10 0.010 0.003 18.22 8.2.9 0.006 0.003 19.83 8.2.8 0.009 0.000 18.18 8.2.7 0.006 0.003 18.17 8.2.6 0.003 0.006 18.05 8.2.5 0.003 0.007 18.41 8.2.4 0.003 0.005 20.75 8.2.3 0.008 0.000 19.63 8.2.2 0.006 0.003 18.33 8.2.1 0.005 0.003 18.49 8.2.0 0.006 0.003 18.34 8.1.28 0.014 0.007 25.92 8.1.27 0.012 0.000 23.99 8.1.26 0.016 0.006 26.35 8.1.25 0.007 0.014 28.09 8.1.24 0.003 0.006 22.46 8.1.23 0.007 0.007 20.89 8.1.22 0.008 0.003 18.16 8.1.21 0.009 0.000 18.77 8.1.20 0.003 0.007 17.73 8.1.19 0.005 0.005 17.60 8.1.18 0.003 0.006 18.10 8.1.17 0.004 0.004 18.84 8.1.16 0.006 0.003 19.14 8.1.15 0.004 0.004 20.33 8.1.14 0.000 0.008 19.31 8.1.13 0.004 0.007 17.63 8.1.12 0.000 0.009 17.73 8.1.11 0.004 0.004 17.72 8.1.10 0.004 0.007 17.74 8.1.9 0.003 0.006 17.61 8.1.8 0.007 0.003 17.75 8.1.7 0.003 0.006 17.70 8.1.6 0.003 0.006 17.85 8.1.5 0.010 0.000 17.77 8.1.4 0.008 0.000 17.82 8.1.3 0.008 0.000 17.96 8.1.2 0.000 0.009 17.88 8.1.1 0.003 0.006 17.84 8.1.0 0.006 0.006 17.87 8.0.30 0.003 0.006 20.03 8.0.29 0.000 0.008 17.25 8.0.28 0.000 0.008 18.69 8.0.27 0.006 0.006 17.46 8.0.26 0.004 0.004 17.21 8.0.25 0.000 0.008 17.25 8.0.24 0.005 0.006 17.41 8.0.23 0.005 0.003 17.32 8.0.22 0.003 0.006 17.30 8.0.21 0.000 0.008 17.31 8.0.20 0.007 0.000 17.21 8.0.19 0.000 0.009 17.32 8.0.18 0.004 0.004 17.26 8.0.17 0.012 0.000 17.17 8.0.16 0.003 0.005 17.28 8.0.15 0.004 0.004 17.12 8.0.14 0.007 0.004 17.13 8.0.13 0.000 0.008 13.71 8.0.12 0.004 0.004 17.24 8.0.11 0.000 0.008 17.30 8.0.10 0.003 0.005 17.27 8.0.9 0.004 0.004 17.17 8.0.8 0.011 0.008 17.22 8.0.7 0.000 0.008 17.29 8.0.6 0.000 0.008 17.33 8.0.5 0.003 0.006 17.29 8.0.3 0.009 0.016 17.36 8.0.2 0.013 0.011 17.58 8.0.1 0.003 0.006 17.14 8.0.0 0.010 0.010 16.90 7.4.33 0.005 0.000 16.71 7.4.32 0.004 0.004 16.78 7.4.30 0.003 0.003 16.73 7.4.29 0.005 0.003 16.88 7.4.28 0.003 0.006 16.88 7.4.27 0.000 0.008 16.78 7.4.26 0.004 0.004 16.75 7.4.25 0.003 0.005 16.82 7.4.24 0.004 0.004 16.90 7.4.23 0.004 0.004 16.71 7.4.22 0.011 0.011 16.91 7.4.21 0.013 0.006 16.83 7.4.20 0.005 0.003 16.73 7.4.15 0.019 0.003 17.40 7.4.14 0.011 0.013 17.86 7.4.13 0.010 0.019 16.90 7.4.12 0.012 0.012 16.87 7.4.11 0.010 0.010 16.61 7.4.10 0.012 0.009 16.76 7.4.9 0.012 0.009 16.74 7.4.8 0.013 0.010 19.39 7.4.7 0.010 0.016 16.64 7.4.6 0.009 0.009 16.84 7.4.5 0.007 0.007 16.98 7.4.4 0.013 0.006 16.82 7.4.3 0.005 0.014 16.49 7.4.0 0.003 0.013 15.18 7.3.33 0.003 0.003 13.55 7.3.32 0.003 0.003 13.46 7.3.31 0.009 0.000 16.51 7.3.30 0.004 0.004 16.61 7.3.29 0.004 0.004 16.51 7.3.28 0.012 0.012 16.62 7.3.27 0.017 0.003 17.40 7.3.26 0.017 0.008 16.64 7.3.25 0.018 0.008 16.80 7.3.24 0.011 0.013 16.64 7.3.23 0.013 0.007 16.60 7.3.21 0.013 0.007 16.83 7.3.20 0.013 0.016 16.68 7.3.19 0.007 0.014 16.61 7.3.18 0.015 0.003 16.61 7.3.17 0.012 0.013 16.62 7.3.16 0.016 0.013 16.87 7.2.33 0.009 0.012 16.72 7.2.32 0.007 0.014 17.11 7.2.31 0.021 0.000 17.04 7.2.30 0.003 0.018 17.07 7.2.29 0.018 0.003 17.09 7.2.6 0.010 0.003 16.97 7.1.20 0.010 0.003 15.94 7.1.11 0.024 0.009 16.59 7.1.10 0.034 0.006 16.28 7.1.9 0.034 0.014 16.35 7.1.8 0.021 0.015 16.78 7.1.7 0.023 0.010 15.30 7.1.6 0.035 0.010 33.38 7.1.5 0.035 0.014 33.42 7.1.4 0.036 0.010 32.92 7.1.3 0.034 0.016 32.95 7.1.2 0.036 0.013 33.16 7.1.1 0.022 0.015 14.75 7.1.0 0.020 0.017 14.88 7.0.25 0.022 0.013 16.26 7.0.24 0.028 0.006 15.82 7.0.23 0.022 0.006 16.29 7.0.22 0.059 0.016 16.31 7.0.21 0.023 0.010 15.05 7.0.20 0.025 0.006 15.25 7.0.19 0.025 0.009 15.07 7.0.18 0.021 0.012 14.63 7.0.17 0.023 0.010 14.57 7.0.16 0.025 0.009 14.70 7.0.15 0.040 0.013 14.56 7.0.14 0.032 0.010 14.50 7.0.13 0.029 0.007 15.11 7.0.12 0.024 0.010 15.08 7.0.11 0.037 0.017 14.86 7.0.10 0.026 0.010 14.41 7.0.9 0.037 0.013 14.66 7.0.8 0.026 0.010 14.84 7.0.7 0.037 0.000 14.65 7.0.6 0.020 0.014 14.55 7.0.5 0.023 0.013 14.63 7.0.4 0.119 0.007 14.76 7.0.3 0.023 0.010 14.91 7.0.2 0.052 0.010 14.84 7.0.1 0.029 0.007 14.67 7.0.0 0.029 0.013 14.76
preferences:dark mode live preview
66.55 ms | 401 KiB | 5 Q