@ 2017-10-29T18:57:35Z <?php
error_reporting(-1);
abstract class AbstractWorker{
public $rank;
public $isBoss;
public $count;
public $coffeeConsumption;
public $salary;
public $printedPages;
public function __construct($count, $rank, $isBoss) {
$this->rank = $rank;
$this->count = $count;
$this->isBoss = $isBoss;
}
function CalculationOfInformation($rank, $isBoss){
if ($this->rank == 2){
$this->salary = $this->salary * 1.25 * $this->count;
} elseif ($this->rank == 3){
$this->salary = $this->salary * 1.5 * $this->count;
} else {
$this->salary = $this->salary * $this->count;
}
$this->coffeeConsumption = $this->coffeeConsumption * $this->count;
$this->printedPages = $this->printedPages * $this->count;
if ($this->isBoss == 1){
$this->salary *= 1.5;
$this->coffeeConsumption *= 2;
$this->printedPages = 0;
}
}
public function print($value){
return $value;
}
}
class Manager extends AbstractWorker{
public $coffeeConsumption = 20;
public $salary = 500;
public $printedPages = 200;
}
class Marketer extends AbstractWorker{
public $coffeeConsumption = 15;
public $salary = 400;
public $printedPages = 150;
}
class Engineer extends AbstractWorker{
public $coffeeConsumption = 5;
public $salary = 200;
public $printedPages = 50;
}
class Analyst extends AbstractWorker{
public $coffeeConsumption = 50;
public $salary = 800;
public $printedPages = 5;
}
class Department {
public $name;
public $workers = array();
public function __construct($name) {
$this->name = $name;
}
public function addWorkers(AbstractWorker $worker){
$worker->CalculationOfInformation($worker->rank, $worker->isBoss);
$this->workers[] = $worker;
}
public function getInformation(){
$information = array(
"name" => 0,
"count" => 0,
"coffee" => 0,
"salary" => 0,
"pages" => 0,
"salaryDivedePagas" => 0
);
foreach ($this->workers as $worker) {
$information["count"] += $worker->print($worker->count);
$information["coffee"] += $worker->print($worker->coffeeConsumption);
$information["salary"] += $worker->print($worker->salary);
$information["pages"] += $worker->print($worker->printedPages);
}
$information["name"] = $this->name;
$information["salaryDividePages"] = $information["salary"] / $information["pages"];
return $information;
}
}
class Company {
public $departments = array();
public $col = array(30, 8, 30, 8, 8, 15);
public function addDepartment(Department $name){
$this->departments[] = $name;
}
public function padRight($string, $length){
echo $string;
echo str_repeat(" ", $length - mb_strlen($string));
}
public function printString($array, $col){
echo $this->padRight($array[0], $this->col[0]) .
$this->padRight($array[1], $this->col[1]) .
$this->padRight($array[2], $this->col[2]).
$this->padRight($array[3], $this->col[3]) .
$this->padRight($array[4], $this->col[4]) .
$this->padRight($array[5], $this->col[5]);
echo "\n\n";
}
public function printColumnName(){
$columnName = array("Департамент", "сотр.", "тург", "кофе", "cтр.", "тугр./стр.");
// echo $this->padRight("Департамент", $this->col[0]) .
// $this->padRight("сотр.", $this->col[1]) .
// $this->padRight("тург.", $this->col[2]).
// $this->padRight("кофе", $this->col[3]) .
// $this->padRight("стр.", $this->col[4]) .
// $this->padRight("тугр./стр.", $this->col[5]);
// echo "\n\n";
printString($columnName, $this->col);
}
public function printDepartment(){
foreach ($this->departments as $department) {
$information = $department->getInformation();
echo $this->padRight($information["name"], $this->col[0]).
$this->padRight($information["count"], $this->col[1]).
$this->padRight($information["coffee"], $this->col[2]).
$this->padRight($information["salary"], $this->col[3]).
$this->padRight($information["pages"], $this->col[4]).
$this->padRight($information["salaryDividePages"], $this->col[5]);
echo "\n";
}
echo "\n";
}
public function printTotalValue(){
$totalCoffee = 0;
$totalWorkers = 0;
$totalSalary = 0;
$totalPages = 0;
$totalSalaryDivedePages = 0;
$totalValue = array();
foreach ($this->departments as $department) {
$totalValues = $department->getInformation();
$totalCoffee += $totalValues["coffee"];
$totalWorkers += $totalValues["count"];
$totalSalary += $totalValues["salary"];
$totalPages += $totalValues["pages"];
$totalSalaryDivedePages += $totalValues["salaryDividePages"];
}
echo $this->padRight("Всего", $this->col[0]).
$this->padRight($totalWorkers, $this->col[1]).
$this->padRight($totalSalary, $this->col[2]).
$this->padRight($totalCoffee, $this->col[3]).
$this->padRight($totalPages, $this->col[4]).
$this->padRight($totalSalaryDivedePages, $this->col[5]);
echo "\n";
}
public function printAverageValue(){
$averageCoffee = 0;
$averageWorkers = 0;
$averageSalary = 0;
$averagePages = 0;
$averageSalaryDivedePages = 0;
$averageValue = array();
foreach ($this->departments as $department) {
$averageValues = $department->getInformation();
$averageCoffee += $averageValues["coffee"];
$averageWorkers += $averageValues["count"];
$averageSalary += $averageValues["salary"];
$averagePages += $averageValues["pages"];
$averageSalaryDivedePages += $averageValues["salaryDividePages"];
}
$averageCoffee /= count($this->departments);
$averageSalary /= count($this->departments);
$averageWorkers /= count($this->departments);
$averagePages /= count($this->departments);
$averageSalaryDivedePages /= count($this->departments);
echo $this->padRight("Среднее", $this->col[0]).
$this->padRight($averageWorkers, $this->col[1]).
$this->padRight($averageSalary, $this->col[2]).
$this->padRight($averageCoffee, $this->col[3]).
$this->padRight($averagePages, $this->col[4]).
$this->padRight($averageSalaryDivedePages, $this->col[5]);
}
}
$vektor = new Company;
$procurementDepartment = new Department("Закупок");
$procurementDepartment->addWorkers(new Manager(9, 1, 0));
$procurementDepartment->addWorkers(new Manager(3, 2, 0));
$procurementDepartment->addWorkers(new Manager(2, 3, 0));
$procurementDepartment->addWorkers(new Marketer(2, 1, 0));
$procurementDepartment->addWorkers(new Manager(1, 2, 1));
$sellingDepartment = new Department("Продаж");
$sellingDepartment->addWorkers(new Manager(12, 1, 0));
$sellingDepartment->addWorkers(new Marketer(6, 1, 0));
$sellingDepartment->addWorkers(new Analyst(3, 1, 0));
$sellingDepartment->addWorkers(new Analyst(2, 2, 0));
$sellingDepartment->addWorkers(new Marketer(1, 2, 1));
$advertisingDepartment = new Department("Рекламы");
$advertisingDepartment->addWorkers(new Marketer(15, 1, 0));
$advertisingDepartment->addWorkers(new Marketer(10, 2, 0));
$advertisingDepartment->addWorkers(new Manager(8, 1, 0));
$advertisingDepartment->addWorkers(new Engineer(2, 1, 0));
$advertisingDepartment->addWorkers(new Marketer(1, 3, 1));
$logisticsDepartment = new Department("Логистики");
$logisticsDepartment->addWorkers(new Manager(13, 1, 0));
$logisticsDepartment->addWorkers(new Manager(5, 2, 0));
$logisticsDepartment->addWorkers(new Engineer(5, 1, 0));
$logisticsDepartment->addWorkers(new Manager(1, 1, 1));
$vektor->addDepartment($procurementDepartment);
$vektor->addDepartment($sellingDepartment);
$vektor->addDepartment($advertisingDepartment);
$vektor->addDepartment($logisticsDepartment);
$vektor->printColumnName();
$vektor->printDepartment();
$vektor->printTotalValue();
$vektor->printAverageValue();
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.007 0.011 17.00 8.3.6 0.006 0.009 17.00 8.3.5 0.017 0.003 16.72 8.3.4 0.012 0.003 18.86 8.3.3 0.012 0.006 19.12 8.3.2 0.004 0.004 20.43 8.3.1 0.000 0.008 23.48 8.3.0 0.008 0.000 23.58 8.2.19 0.019 0.004 16.75 8.2.18 0.009 0.009 16.88 8.2.17 0.008 0.008 22.96 8.2.16 0.004 0.011 20.66 8.2.15 0.004 0.004 25.66 8.2.14 0.011 0.007 24.66 8.2.13 0.004 0.004 20.54 8.2.12 0.000 0.007 26.35 8.2.11 0.006 0.003 21.08 8.2.10 0.009 0.003 18.16 8.2.9 0.004 0.004 20.77 8.2.8 0.006 0.003 20.62 8.2.7 0.006 0.003 17.88 8.2.6 0.005 0.003 18.05 8.2.5 0.004 0.004 18.34 8.2.4 0.005 0.003 20.59 8.2.3 0.004 0.004 19.49 8.2.2 0.004 0.004 18.25 8.2.1 0.000 0.008 18.17 8.2.0 0.007 0.000 18.17 8.1.28 0.009 0.009 25.92 8.1.27 0.004 0.004 22.23 8.1.26 0.005 0.003 26.35 8.1.25 0.008 0.000 28.09 8.1.24 0.004 0.004 22.32 8.1.23 0.012 0.000 21.03 8.1.22 0.009 0.000 17.89 8.1.21 0.004 0.004 18.97 8.1.20 0.003 0.006 17.60 8.1.19 0.008 0.000 17.66 8.1.18 0.003 0.006 18.10 8.1.17 0.005 0.003 18.65 8.1.16 0.007 0.000 18.99 8.1.15 0.000 0.008 19.06 8.1.14 0.005 0.003 19.67 8.1.13 0.005 0.002 18.98 8.1.12 0.000 0.008 17.64 8.1.11 0.004 0.004 17.66 8.1.10 0.008 0.000 17.59 8.1.9 0.008 0.003 17.64 8.1.8 0.004 0.004 17.52 8.1.7 0.004 0.004 17.57 8.1.6 0.008 0.004 17.64 8.1.5 0.003 0.006 17.75 8.1.4 0.003 0.005 17.69 8.1.3 0.004 0.007 17.88 8.1.2 0.004 0.004 17.83 8.1.1 0.000 0.008 17.76 8.1.0 0.005 0.003 17.68 8.0.30 0.004 0.004 21.94 8.0.29 0.004 0.004 17.13 8.0.28 0.004 0.004 18.54 8.0.27 0.004 0.004 17.33 8.0.26 0.003 0.003 17.11 8.0.25 0.000 0.007 17.24 8.0.24 0.000 0.008 17.17 8.0.23 0.007 0.000 17.19 8.0.22 0.000 0.008 17.10 8.0.21 0.000 0.007 16.97 8.0.20 0.000 0.007 17.04 8.0.19 0.004 0.004 17.18 8.0.18 0.004 0.004 17.05 8.0.17 0.008 0.000 17.09 8.0.16 0.000 0.007 16.98 8.0.15 0.004 0.004 16.95 8.0.14 0.008 0.000 17.01 8.0.13 0.000 0.006 13.47 8.0.12 0.004 0.004 17.06 8.0.11 0.000 0.011 17.09 8.0.10 0.000 0.008 17.07 8.0.9 0.000 0.008 17.00 8.0.8 0.004 0.012 17.18 8.0.7 0.004 0.004 17.09 8.0.6 0.006 0.003 17.02 8.0.5 0.007 0.000 16.98 8.0.3 0.009 0.009 17.27 8.0.2 0.010 0.011 17.45 8.0.1 0.008 0.000 17.24 8.0.0 0.010 0.009 17.15 7.4.33 0.000 0.007 15.55 7.4.32 0.003 0.003 16.84 7.4.30 0.003 0.003 16.78 7.4.29 0.000 0.007 16.78 7.4.28 0.004 0.004 16.66 7.4.27 0.004 0.004 16.70 7.4.26 0.007 0.004 16.61 7.4.25 0.000 0.008 16.71 7.4.24 0.004 0.004 16.79 7.4.23 0.004 0.004 16.80 7.4.22 0.020 0.003 16.52 7.4.21 0.006 0.011 16.75 7.4.20 0.004 0.004 16.69 7.4.16 0.010 0.006 16.68 7.4.15 0.009 0.009 17.40 7.4.14 0.012 0.008 17.86 7.4.13 0.006 0.012 16.66 7.4.12 0.009 0.009 16.67 7.4.11 0.015 0.003 16.76 7.4.10 0.012 0.006 16.76 7.4.9 0.007 0.011 16.66 7.4.8 0.012 0.006 19.39 7.4.7 0.010 0.007 16.60 7.4.6 0.009 0.006 16.66 7.4.5 0.007 0.007 16.84 7.4.4 0.007 0.010 16.83 7.4.3 0.011 0.007 16.74 7.4.0 0.003 0.005 14.99 7.3.33 0.003 0.003 13.60 7.3.32 0.006 0.000 13.46 7.3.31 0.007 0.000 16.45 7.3.30 0.003 0.006 16.51 7.3.29 0.000 0.007 16.48 7.3.28 0.009 0.009 16.60 7.3.27 0.014 0.003 17.40 7.3.26 0.010 0.008 16.73 7.3.25 0.009 0.010 16.62 7.3.24 0.008 0.009 16.68 7.3.23 0.013 0.004 16.64 7.3.21 0.012 0.006 16.63 7.3.20 0.007 0.010 16.76 7.3.19 0.009 0.009 16.48 7.3.18 0.008 0.008 16.61 7.3.17 0.008 0.008 16.53 7.3.16 0.012 0.006 16.57 7.2.33 0.006 0.012 16.72 7.2.32 0.009 0.015 16.96 7.2.31 0.011 0.008 16.92 7.2.30 0.007 0.010 16.75 7.2.29 0.009 0.009 16.79 7.2.6 0.004 0.008 16.96 7.1.20 0.004 0.007 15.93 7.1.11 0.000 0.013 18.28 7.1.10 0.003 0.010 18.17 7.1.9 0.000 0.013 18.09 7.1.8 0.011 0.007 18.05 7.1.7 0.009 0.005 17.01 7.1.6 0.020 0.007 35.06 7.1.5 0.022 0.007 34.72 7.1.4 0.013 0.013 34.41 7.1.3 0.020 0.010 34.47 7.1.2 0.015 0.011 34.57 7.1.1 0.009 0.006 16.67 7.1.0 0.004 0.011 16.54 7.0.25 0.006 0.006 17.62 7.0.24 0.009 0.006 17.73 7.0.23 0.003 0.015 17.58 7.0.22 0.004 0.014 17.40 7.0.21 0.006 0.007 16.61 7.0.20 0.004 0.009 16.53 7.0.19 0.006 0.006 16.89 7.0.18 0.003 0.010 16.33 7.0.17 0.006 0.006 16.21 7.0.16 0.006 0.012 16.35 7.0.15 0.003 0.012 16.20 7.0.14 0.006 0.009 16.27 7.0.13 0.003 0.009 16.50 7.0.12 0.004 0.008 16.54 7.0.11 0.006 0.008 16.41 7.0.10 0.009 0.003 16.23 7.0.9 0.005 0.008 16.38 7.0.8 0.006 0.009 16.40 7.0.7 0.003 0.010 16.24 7.0.6 0.003 0.009 16.29 7.0.5 0.003 0.013 16.24 7.0.4 0.011 0.003 16.61 7.0.3 0.008 0.005 16.36 7.0.2 0.000 0.013 16.34 7.0.1 0.001 0.012 16.42 7.0.0 0.000 0.013 16.27
preferences:dark mode live preview
18.42 ms | 401 KiB | 5 Q