@ 2017-11-17T23:52:04Z <?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);
}
}
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 HiringWorkers
{
public function addWorkersToDepartment(Department $department, string $profession, int $count, int $rang, int $isBoss): void
{
if ($profession == Manager::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Manager($rang, $isBoss));
}
} elseif ($profession == Marketer::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Marketer($rang, $isBoss));
}
} elseif ($profession == Engineer::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Engineer ($rang, $isBoss));
}
} elseif ($profession == Analyst::class){
for ($i = 0; $i < $count; $i++){
$department->addWorker(new Analyst ($rang, $isBoss));
}
}
}
}
$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);
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.004 0.018 17.00 8.3.6 0.013 0.013 16.75 8.3.5 0.009 0.005 18.34 8.3.4 0.010 0.006 19.07 8.3.3 0.015 0.000 19.10 8.3.2 0.006 0.003 20.54 8.3.1 0.003 0.006 23.84 8.3.0 0.004 0.004 23.48 8.2.19 0.013 0.010 16.88 8.2.18 0.013 0.003 25.92 8.2.17 0.008 0.008 19.21 8.2.16 0.007 0.007 22.96 8.2.15 0.004 0.004 25.66 8.2.14 0.004 0.004 24.66 8.2.13 0.005 0.003 22.07 8.2.12 0.008 0.000 26.35 8.2.11 0.003 0.006 20.64 8.2.10 0.008 0.004 17.91 8.2.9 0.006 0.003 22.36 8.2.8 0.000 0.008 17.97 8.2.7 0.008 0.000 18.18 8.2.6 0.003 0.005 18.34 8.2.5 0.005 0.005 18.47 8.2.4 0.006 0.003 20.76 8.2.3 0.005 0.003 19.53 8.2.2 0.004 0.004 18.25 8.2.1 0.005 0.005 18.25 8.2.0 0.005 0.002 18.25 8.1.28 0.006 0.009 25.92 8.1.27 0.005 0.003 24.66 8.1.26 0.000 0.008 26.35 8.1.25 0.015 0.003 28.09 8.1.24 0.010 0.003 22.25 8.1.23 0.008 0.004 22.82 8.1.22 0.008 0.000 17.91 8.1.21 0.008 0.000 19.10 8.1.20 0.006 0.003 17.48 8.1.19 0.003 0.006 17.48 8.1.18 0.008 0.000 18.10 8.1.17 0.003 0.005 18.71 8.1.16 0.003 0.006 19.10 8.1.15 0.000 0.007 20.52 8.1.14 0.003 0.005 19.29 8.1.13 0.003 0.006 19.16 8.1.12 0.004 0.004 17.61 8.1.11 0.006 0.003 17.55 8.1.10 0.004 0.004 17.72 8.1.9 0.000 0.008 17.55 8.1.8 0.004 0.004 17.64 8.1.7 0.000 0.007 17.65 8.1.6 0.006 0.003 17.76 8.1.5 0.005 0.005 17.70 8.1.4 0.008 0.000 17.75 8.1.3 0.004 0.004 17.97 8.1.2 0.004 0.004 17.89 8.1.1 0.003 0.005 17.86 8.1.0 0.004 0.004 17.78 8.0.30 0.004 0.004 20.11 8.0.29 0.003 0.006 17.00 8.0.28 0.004 0.004 18.71 8.0.27 0.008 0.000 17.45 8.0.26 0.004 0.004 19.10 8.0.25 0.006 0.003 17.27 8.0.24 0.000 0.009 17.26 8.0.23 0.004 0.004 17.19 8.0.22 0.000 0.007 17.20 8.0.21 0.004 0.004 17.09 8.0.20 0.000 0.008 17.18 8.0.19 0.004 0.004 17.21 8.0.18 0.000 0.008 17.27 8.0.17 0.004 0.004 17.21 8.0.16 0.009 0.000 17.24 8.0.15 0.005 0.003 17.15 8.0.14 0.006 0.003 17.07 8.0.13 0.000 0.006 13.61 8.0.12 0.000 0.008 17.21 8.0.11 0.000 0.009 17.17 8.0.10 0.008 0.000 17.34 8.0.9 0.003 0.005 17.18 8.0.8 0.010 0.006 17.18 8.0.7 0.003 0.005 17.23 8.0.6 0.006 0.003 17.13 8.0.5 0.004 0.004 17.21 8.0.3 0.008 0.011 17.38 8.0.2 0.010 0.011 17.45 8.0.1 0.000 0.008 17.34 8.0.0 0.012 0.008 16.96 7.4.33 0.006 0.000 15.55 7.4.32 0.000 0.007 16.68 7.4.30 0.000 0.007 16.80 7.4.29 0.000 0.010 16.79 7.4.28 0.004 0.004 16.73 7.4.27 0.004 0.004 16.82 7.4.26 0.005 0.003 16.81 7.4.25 0.004 0.004 16.65 7.4.24 0.007 0.000 16.74 7.4.23 0.000 0.008 16.91 7.4.22 0.010 0.017 16.71 7.4.21 0.006 0.010 16.78 7.4.20 0.000 0.007 16.69 7.4.16 0.010 0.007 16.84 7.4.15 0.017 0.003 17.40 7.4.14 0.010 0.009 17.86 7.4.13 0.008 0.011 16.91 7.4.12 0.013 0.008 16.75 7.4.11 0.000 0.017 16.75 7.4.10 0.003 0.015 16.78 7.4.9 0.015 0.004 16.53 7.4.8 0.009 0.012 19.39 7.4.7 0.006 0.012 16.85 7.4.6 0.003 0.014 16.55 7.4.5 0.009 0.006 16.61 7.4.4 0.013 0.006 16.63 7.4.3 0.009 0.008 16.77 7.4.0 0.007 0.007 15.08 7.3.33 0.000 0.006 13.63 7.3.32 0.000 0.006 13.62 7.3.31 0.000 0.007 16.66 7.3.30 0.007 0.000 16.47 7.3.29 0.009 0.009 16.61 7.3.28 0.009 0.007 16.55 7.3.27 0.011 0.008 17.40 7.3.26 0.012 0.013 16.75 7.3.25 0.015 0.006 16.72 7.3.24 0.012 0.008 16.71 7.3.23 0.007 0.011 16.63 7.3.21 0.010 0.016 16.59 7.3.20 0.014 0.007 16.77 7.3.19 0.017 0.007 16.66 7.3.18 0.015 0.003 16.63 7.3.17 0.010 0.007 16.59 7.3.16 0.004 0.015 16.71 7.3.1 0.006 0.009 16.77 7.3.0 0.012 0.000 16.77 7.2.33 0.019 0.000 16.91 7.2.32 0.012 0.006 17.04 7.2.31 0.013 0.006 16.78 7.2.30 0.010 0.014 16.83 7.2.29 0.010 0.007 17.09 7.2.13 0.006 0.009 17.21 7.2.12 0.000 0.012 16.97 7.2.11 0.009 0.000 16.75 7.2.10 0.004 0.011 17.09 7.2.9 0.003 0.010 16.69 7.2.8 0.000 0.014 16.85 7.2.7 0.006 0.012 16.99 7.2.6 0.009 0.005 16.93 7.2.5 0.009 0.006 16.89 7.2.4 0.012 0.003 16.78 7.2.3 0.004 0.011 16.92 7.2.2 0.003 0.010 16.84 7.2.1 0.010 0.003 17.03 7.2.0 0.004 0.011 16.89 7.1.25 0.010 0.006 15.66 7.1.20 0.007 0.004 15.64 7.1.11 0.024 0.012 18.03 7.1.10 0.031 0.016 18.09 7.1.9 0.018 0.015 16.26 7.1.8 0.026 0.015 16.23 7.1.7 0.021 0.011 15.56 7.1.6 0.051 0.007 33.53 7.1.5 0.037 0.016 33.23 7.1.4 0.040 0.003 32.88 7.1.3 0.039 0.007 32.93 7.1.2 0.033 0.013 32.93 7.1.1 0.023 0.007 15.04 7.1.0 0.039 0.010 15.10 7.0.25 0.024 0.014 17.61 7.0.24 0.040 0.009 17.82 7.0.23 0.024 0.009 15.83 7.0.22 0.029 0.011 16.05 7.0.21 0.021 0.010 14.88 7.0.20 0.019 0.012 14.98 7.0.19 0.022 0.009 15.17 7.0.18 0.022 0.009 14.60 7.0.17 0.018 0.010 14.57 7.0.16 0.023 0.004 14.66 7.0.15 0.030 0.000 14.67 7.0.14 0.026 0.003 14.46 7.0.13 0.022 0.006 14.80 7.0.12 0.022 0.010 14.91 7.0.11 0.021 0.009 14.76 7.0.10 0.021 0.010 14.61 7.0.9 0.069 0.003 14.71 7.0.8 0.018 0.012 14.78 7.0.7 0.022 0.011 14.55 7.0.6 0.025 0.007 14.55 7.0.5 0.023 0.008 14.64 7.0.4 0.020 0.013 14.98 7.0.3 0.027 0.003 14.84 7.0.2 0.024 0.007 14.52 7.0.1 0.028 0.003 14.68 7.0.0 0.029 0.016 14.81
preferences:dark mode live preview
56.88 ms | 401 KiB | 5 Q