@ 2018-01-14T19:28:02Z <?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]->getRank()){
$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));
foreach ($department->getWorkers() as $key => $worker) {
if ($worker == $workersOfCertainProfession[0]){
$department->deleteWorker($key);
unset($workersOfCertainProfession[0]);
sort($workersOfCertainProfession);
}
if (count($workersOfCertainProfession) == 0){
break;
}
}
}
}
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->increaseManagers($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.4.12 0.009 0.011 22.07 8.4.11 0.011 0.011 22.39 8.4.10 0.005 0.004 19.03 8.4.9 0.004 0.006 20.77 8.4.8 0.009 0.006 19.11 8.4.7 0.009 0.011 19.09 8.4.6 0.008 0.005 20.56 8.4.5 0.014 0.008 18.64 8.4.4 0.009 0.006 19.28 8.4.3 0.007 0.013 17.91 8.4.2 0.018 0.003 19.41 8.4.1 0.003 0.007 19.54 8.3.25 0.008 0.004 17.59 8.3.24 0.012 0.009 16.69 8.3.23 0.012 0.009 16.83 8.3.22 0.007 0.002 19.41 8.3.21 0.010 0.010 16.81 8.3.20 0.007 0.003 16.80 8.3.19 0.006 0.003 17.28 8.3.18 0.012 0.008 19.05 8.3.17 0.006 0.013 19.05 8.3.16 0.006 0.013 18.43 8.3.15 0.009 0.009 19.22 8.3.14 0.003 0.006 17.29 8.3.13 0.013 0.000 16.98 8.3.12 0.006 0.003 20.75 8.3.11 0.008 0.004 18.49 8.3.10 0.003 0.007 17.00 8.3.9 0.010 0.007 16.76 8.3.8 0.005 0.005 17.97 8.3.7 0.016 0.006 17.13 8.3.6 0.000 0.016 18.55 8.3.5 0.010 0.005 17.25 8.3.4 0.007 0.010 19.09 8.3.3 0.013 0.010 18.91 8.3.2 0.007 0.003 19.15 8.3.1 0.004 0.004 23.59 8.3.0 0.003 0.006 19.51 8.2.29 0.012 0.009 19.40 8.2.28 0.012 0.007 20.05 8.2.27 0.007 0.013 16.69 8.2.26 0.009 0.000 17.54 8.2.25 0.003 0.006 17.01 8.2.24 0.013 0.003 17.43 8.2.23 0.000 0.008 20.94 8.2.22 0.006 0.003 24.06 8.2.21 0.004 0.004 26.77 8.2.20 0.003 0.007 16.88 8.2.19 0.006 0.010 16.86 8.2.18 0.009 0.006 18.29 8.2.17 0.010 0.007 22.96 8.2.16 0.007 0.011 20.86 8.2.15 0.003 0.006 24.18 8.2.14 0.003 0.005 24.66 8.2.13 0.005 0.003 19.63 8.2.12 0.005 0.003 26.35 8.2.11 0.006 0.003 22.28 8.2.10 0.006 0.006 17.94 8.2.9 0.000 0.009 18.19 8.2.8 0.000 0.008 19.46 8.2.7 0.000 0.010 18.17 8.2.6 0.004 0.004 18.41 8.2.5 0.005 0.003 18.53 8.2.4 0.006 0.003 20.67 8.2.3 0.003 0.005 19.70 8.2.2 0.000 0.008 18.41 8.2.1 0.008 0.000 18.38 8.2.0 0.008 0.000 18.64 8.1.33 0.014 0.007 18.62 8.1.32 0.012 0.008 17.87 8.1.31 0.007 0.011 16.91 8.1.30 0.007 0.003 16.19 8.1.29 0.007 0.004 30.84 8.1.28 0.012 0.006 25.92 8.1.27 0.007 0.013 23.99 8.1.26 0.003 0.006 26.35 8.1.25 0.004 0.004 28.09 8.1.24 0.006 0.003 22.37 8.1.23 0.008 0.003 21.27 8.1.22 0.000 0.009 17.91 8.1.21 0.009 0.000 18.77 8.1.20 0.006 0.003 17.60 8.1.19 0.000 0.008 17.60 8.1.18 0.006 0.003 18.10 8.1.17 0.004 0.004 18.93 8.1.16 0.000 0.008 19.04 8.1.15 0.000 0.008 20.61 8.1.14 0.000 0.009 19.36 8.1.13 0.004 0.004 17.67 8.1.12 0.003 0.005 17.77 8.1.11 0.003 0.006 17.70 8.1.10 0.009 0.000 17.77 8.1.9 0.004 0.004 17.74 8.1.8 0.004 0.004 17.73 8.1.7 0.007 0.004 17.71 8.1.6 0.003 0.006 17.81 8.1.5 0.008 0.000 17.81 8.1.4 0.006 0.003 17.89 8.1.3 0.004 0.004 17.99 8.1.2 0.008 0.000 18.05 8.1.1 0.000 0.008 17.95 8.1.0 0.009 0.000 17.78 8.0.30 0.004 0.004 20.46 8.0.29 0.003 0.006 17.00 8.0.28 0.005 0.002 18.79 8.0.27 0.005 0.002 17.61 8.0.26 0.005 0.002 17.22 8.0.25 0.000 0.007 17.37 8.0.24 0.004 0.004 17.34 8.0.23 0.005 0.003 17.23 8.0.22 0.004 0.004 17.27 8.0.21 0.008 0.000 17.35 8.0.20 0.000 0.007 17.35 8.0.19 0.006 0.003 17.40 8.0.18 0.000 0.008 17.28 8.0.17 0.008 0.006 17.27 8.0.16 0.004 0.004 17.27 8.0.15 0.005 0.003 17.30 8.0.14 0.005 0.003 17.21 8.0.13 0.008 0.003 13.73 8.0.12 0.006 0.003 17.30 8.0.11 0.003 0.006 17.21 8.0.10 0.005 0.003 17.25 8.0.9 0.000 0.008 17.33 8.0.8 0.009 0.015 17.37 8.0.7 0.008 0.000 17.30 8.0.6 0.003 0.005 17.34 8.0.5 0.005 0.003 17.20 8.0.3 0.010 0.013 17.36 8.0.2 0.011 0.011 17.47 8.0.1 0.000 0.008 17.45 8.0.0 0.012 0.011 16.93 7.4.33 0.000 0.006 16.79 7.4.32 0.007 0.000 16.81 7.4.30 0.000 0.007 16.91 7.4.29 0.008 0.000 16.74 7.4.28 0.000 0.008 16.89 7.4.27 0.003 0.005 16.80 7.4.26 0.000 0.008 16.70 7.4.25 0.000 0.008 16.81 7.4.24 0.008 0.000 16.71 7.4.23 0.003 0.006 16.79 7.4.22 0.009 0.000 16.99 7.4.21 0.008 0.008 16.84 7.4.20 0.004 0.004 16.82 7.4.16 0.007 0.011 16.84 7.4.15 0.007 0.015 17.40 7.4.14 0.015 0.009 17.86 7.4.13 0.012 0.008 16.79 7.4.12 0.010 0.011 16.79 7.4.11 0.013 0.006 16.84 7.4.10 0.013 0.009 16.73 7.4.9 0.016 0.003 16.74 7.4.8 0.013 0.006 19.39 7.4.7 0.006 0.014 16.92 7.4.6 0.010 0.007 16.60 7.4.5 0.004 0.012 16.54 7.4.4 0.014 0.006 16.63 7.4.0 0.010 0.007 15.40 7.3.33 0.003 0.003 13.65 7.3.32 0.006 0.000 13.46 7.3.31 0.004 0.004 16.68 7.3.30 0.007 0.000 16.61 7.3.29 0.005 0.002 16.56 7.3.28 0.006 0.010 16.56 7.3.27 0.013 0.006 17.40 7.3.26 0.007 0.013 16.82 7.3.25 0.014 0.008 16.66 7.3.24 0.012 0.010 16.61 7.3.23 0.012 0.006 16.65 7.3.21 0.013 0.006 16.76 7.3.20 0.012 0.006 16.77 7.3.19 0.012 0.006 17.05 7.3.18 0.014 0.003 16.73 7.3.17 0.006 0.012 16.59 7.3.16 0.013 0.006 16.78 7.3.1 0.006 0.009 16.48 7.3.0 0.003 0.011 16.70 7.2.33 0.014 0.006 17.09 7.2.32 0.009 0.018 16.98 7.2.31 0.017 0.004 17.02 7.2.30 0.017 0.003 17.04 7.2.29 0.009 0.009 16.75 7.2.13 0.005 0.010 16.61 7.2.12 0.028 0.006 16.88 7.2.11 0.006 0.009 16.94 7.2.10 0.007 0.007 16.86 7.2.9 0.007 0.007 16.80 7.2.8 0.011 0.000 16.76 7.2.7 0.015 0.013 16.86 7.2.6 0.012 0.011 16.76 7.2.5 0.013 0.010 16.98 7.2.4 0.004 0.015 16.92 7.2.3 0.015 0.007 17.06 7.2.2 0.007 0.010 17.12 7.2.1 0.011 0.005 18.43 7.2.0 0.007 0.009 18.29 7.1.25 0.021 0.012 15.75 7.1.20 0.003 0.010 15.98 7.1.13 0.004 0.011 18.65 7.1.12 0.003 0.012 18.89 7.1.11 0.003 0.011 17.79 7.1.10 0.011 0.003 18.17 7.1.9 0.006 0.010 17.89 7.1.8 0.000 0.014 18.05 7.1.7 0.009 0.006 17.08 7.1.6 0.013 0.013 35.18 7.1.5 0.021 0.014 34.70 7.1.4 0.015 0.012 34.51 7.1.3 0.017 0.010 34.64 7.1.2 0.015 0.012 34.67 7.1.1 0.004 0.011 16.73 7.1.0 0.000 0.020 16.66
preferences:dark mode live preview ace vim emacs key bindings
28.94 ms | 403 KiB | 5 Q