@ 2017-11-12T14:24:55Z <?php
error_reporting(-1);
abstract class AbstractWorker{
private $rank;
private $isBoss;
private $coffee;
private $salary;
private $pages;
public function __construct( $rank, $isBoss) {
$this->rank = $rank;
$this->isBoss = $isBoss;
}
public function getSalary(){
$salary = $this->salary;
if ($this->rank == 2){
$salary = $this->salary * 1.25;
} elseif ($this->rank == 3){
$salary = $this->salary * 1.5;
}
return $salary;
}
public function getCoffee(){
$coffee = $this->coffee;
if ($this->isBoss == 1){
$coffee = $this->coffee * 2;
}
return $coffee;
}
public function getPages(){
$pages = $this->pages;
if ($this->isBoss == 1){
$pages = $this->pages * 0;
}
$pages = 10;
return $pages;
}
}
class Manager extends AbstractWorker{
public $coffee = 20;
public $salary = 500;
public $pages = 200;
}
class Marketer extends AbstractWorker{
public $coffee = 15;
public $salary = 400;
public $pages = 150;
}
class Engineer extends AbstractWorker{
public $coffee = 5;
public $salary = 200;
public $pages = 50;
}
class Analyst extends AbstractWorker{
public $coffee = 50;
public $salary = 800;
public $pages = 5;
}
class Department{
public $name;
public $workers = array();
public function __construct($name) {
$this->name = $name;
}
public function addWorker(AbstractWorker $worker){
$this->workers[] = $worker;
}
public function getNumberWorkers(){
return count($this->workers);
}
public function getDepartmentSalary(){
$totalSalary = 0;
foreach ($this->workers as $worker) {
$totalSalary += $worker->getSalary();
}
return $totalSalary;
}
public function getDepartmentCoffee(){
$totalCoffee = 0;
foreach ($this->workers as $worker) {
$totalCoffee += $worker->getCoffee();
}
return $totalCoffee;
}
public function getDepartmentPages(){
$totalPages = 0;
foreach ($this->workers as $worker) {
$totalPages += $worker->getPages();
}
return $totalPages;
}
// public function getWorkers(){
// return $this->workers;
// }
public function getDepartmentName(){
return $this->name;
}
public function addWorkersToDepartment(string $profession, int $count, int $rang, int $isBoss){
if ($profession == "Manager"){
for ($i = 0; $i < $count; $i++){
//$this->addWorker(Manager $worker($rang, $isBoss));
$this->addWorker(new Manager($rang, $isBoss));
}
} elseif ($profession == "Marketer"){
for ($i = 0; $i < $count; $i++){
$this->addWorker(new Marketer($rang, $isBoss));
}
} elseif ($profession == "Engineer"){
for ($i = 0; $i < $count; $i++){
$this->addWorker(new Engineer ($rang, $isBoss));
}
} elseif ($profession == "Analyst"){
for ($i = 0; $i < $count; $i++){
$this->addWorker(new Engineer ($rang, $isBoss));
}
}
}
}
class Company{
public $departments = array();
public function addDepartment(Department $department){
$this->departments[] = $department;
}
public function getDepartments(){
return $this->departments;
}
public function getDepartmentCount(){
return count($this->departments);
}
}
class Tabel{
private function padLeft($value, $columnLength){
echo $value;
echo str_repeat(" ", $columnLength - mb_strlen($value));
}
private function calculatiotOfOutput(array $informarion){
$col1 = 15;
$col2 = 10;
$col3 = 10;
$col4 = 8;
$col5 = 8;
$col6 = 15;
echo $this->padLeft($informarion["name"], $col1) .
$this->padLeft($informarion["count"], $col2) .
$this->padLeft($informarion["salary"], $col3) .
$this->padLeft($informarion["coffee"], $col4) .
$this->padLeft($informarion["pages"], $col5) .
$this->padLeft($informarion["salaryDividePages"], $col6) . "\n";
}
public function printTabel(Company $company){
$columnName = array("name" => "Департамент",
"count" => "сотр.",
"salary" => "тугр.",
"coffee" => "кофе",
"pages" => "стр.",
"salaryDividePages" => "тугр./стр.");
$this->calculatiotOfOutput($columnName);
$information = array("name" => "",
"count" => 0,
"salary" => 0,
"coffee" => 0,
"pages" => 0,
"salaryDividePages" => 0);
foreach ($company->getDepartments() as $department) {
$information["name"] = $department->getDepartmentName();
$information["count"] = $department->getNumberWorkers();
$information["salary"] = $department->getDepartmentSalary();
$information["coffee"] = $department->getDepartmentCoffee();
$information["pages"] = $department->getDepartmentPages();
$information["salaryDividePages"] = round($department->getDepartmentSalary() / 2, 1);
$this->calculatiotOfOutput($information);
}
echo "\n";
$totalInformation = array("name" => "Всего",
"count" => 0,
"salary" => 0,
"coffee" => 0,
"pages" => 0,
"salaryDividePages" => 0);
$totalInformation["name"] = "Всего";
foreach ($company->getDepartments() as $department) {
$totalInformation["count"] += $department->getNumberWorkers();
$totalInformation["salary"] += $department->getDepartmentSalary();
$totalInformation["coffee"] += $department->getDepartmentCoffee();
$totalInformation["pages"] += $department->getDepartmentPages();
}
$totalInformarion["salaryDividePages"] = round($totalInformation["salary"] / $totalInformation["pages"], 1);
$this->calculatiotOfOutput($totalInformation);
$averageInformation = array("name" => "Среднее",
"count" => $totalInformation["count"] / $company->getDepartmentCount(),
"salary" => $totalInformation["salary"] / $company->getDepartmentCount(),
"coffee" => $totalInformation["coffee"] / $company->getDepartmentCount(),
"pages" => $totalInformation["pages"] / $company->getDepartmentCount(),
"salaryDividePages" => $totalInformation["salaryDividePages"] / $company->getDepartmentCount());
$this->calculatiotOfOutput($averageInformation);
}
}
$vektor = new Company;
$zakupki = new Department("Запуки");
$zakupki->addWorkersToDepartment("Manager", 5, 2, 0);
$vektor->addDepartment($zakupki);
$tabel = new Tabel;
$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.021 0.000 16.38 8.3.5 0.011 0.004 18.19 8.3.4 0.007 0.007 18.71 8.3.3 0.000 0.015 18.84 8.3.2 0.004 0.004 20.38 8.3.1 0.000 0.008 23.31 8.3.0 0.005 0.003 23.66 8.2.18 0.007 0.007 16.63 8.2.17 0.011 0.007 19.08 8.2.16 0.004 0.015 22.96 8.2.15 0.004 0.004 25.66 8.2.14 0.008 0.000 24.66 8.2.13 0.004 0.004 21.96 8.2.12 0.004 0.004 26.35 8.2.11 0.003 0.006 20.29 8.2.10 0.009 0.003 17.89 8.2.9 0.006 0.003 19.25 8.2.8 0.003 0.006 17.97 8.2.7 0.006 0.006 17.75 8.2.6 0.003 0.005 18.05 8.2.5 0.000 0.009 18.10 8.2.4 0.004 0.004 20.50 8.2.3 0.003 0.005 21.15 8.2.2 0.003 0.005 18.20 8.2.1 0.002 0.005 18.15 8.2.0 0.005 0.002 18.07 8.1.28 0.009 0.006 25.92 8.1.27 0.003 0.006 23.97 8.1.26 0.005 0.003 26.35 8.1.25 0.000 0.008 28.09 8.1.24 0.003 0.006 23.96 8.1.23 0.008 0.003 22.07 8.1.22 0.000 0.008 17.80 8.1.21 0.000 0.009 18.77 8.1.20 0.010 0.000 17.48 8.1.19 0.000 0.008 17.35 8.1.18 0.006 0.003 18.10 8.1.17 0.004 0.004 18.93 8.1.16 0.005 0.002 19.04 8.1.15 0.004 0.004 20.67 8.1.14 0.000 0.008 17.70 8.1.13 0.003 0.003 18.83 8.1.12 0.006 0.003 17.54 8.1.11 0.004 0.004 17.45 8.1.10 0.005 0.003 17.57 8.1.9 0.000 0.008 17.41 8.1.8 0.007 0.000 17.48 8.1.7 0.003 0.005 17.41 8.1.6 0.000 0.008 17.71 8.1.5 0.003 0.005 17.65 8.1.4 0.000 0.008 17.62 8.1.3 0.004 0.004 17.70 8.1.2 0.003 0.007 17.78 8.1.1 0.000 0.008 17.70 8.1.0 0.009 0.000 17.59 8.0.30 0.006 0.003 18.77 8.0.29 0.003 0.006 16.88 8.0.28 0.004 0.004 18.63 8.0.27 0.000 0.007 17.39 8.0.26 0.007 0.000 20.73 8.0.25 0.004 0.004 17.22 8.0.24 0.003 0.003 17.18 8.0.23 0.006 0.003 17.17 8.0.22 0.003 0.003 17.18 8.0.21 0.008 0.000 17.09 8.0.20 0.007 0.000 17.02 8.0.19 0.000 0.008 17.14 8.0.18 0.004 0.004 17.15 8.0.17 0.003 0.006 17.12 8.0.16 0.000 0.007 17.05 8.0.15 0.005 0.002 16.92 8.0.14 0.007 0.000 17.07 8.0.13 0.006 0.000 13.50 8.0.12 0.005 0.002 17.00 8.0.11 0.005 0.002 17.09 8.0.10 0.004 0.004 17.15 8.0.9 0.000 0.009 17.21 8.0.8 0.003 0.016 16.98 8.0.7 0.005 0.002 17.09 8.0.6 0.000 0.008 17.11 8.0.5 0.004 0.004 17.16 8.0.3 0.007 0.011 17.23 8.0.2 0.012 0.009 17.40 8.0.1 0.000 0.008 16.98 8.0.0 0.010 0.010 16.73 7.4.33 0.000 0.005 16.79 7.4.32 0.006 0.000 16.46 7.4.30 0.005 0.002 16.49 7.4.29 0.000 0.007 16.69 7.4.28 0.007 0.000 16.48 7.4.27 0.000 0.007 16.74 7.4.26 0.000 0.007 16.53 7.4.25 0.005 0.003 16.56 7.4.24 0.000 0.007 16.58 7.4.23 0.005 0.003 16.59 7.4.22 0.009 0.009 16.77 7.4.21 0.011 0.007 16.77 7.4.20 0.004 0.004 16.50 7.4.16 0.008 0.008 16.58 7.4.15 0.009 0.009 17.40 7.4.14 0.011 0.009 17.86 7.4.13 0.008 0.012 16.59 7.4.12 0.012 0.009 16.65 7.4.11 0.010 0.007 16.53 7.4.10 0.015 0.006 16.74 7.4.9 0.007 0.011 16.61 7.4.8 0.013 0.009 19.39 7.4.7 0.010 0.011 16.41 7.4.6 0.015 0.006 16.54 7.4.5 0.009 0.009 16.38 7.4.4 0.010 0.006 16.70 7.4.3 0.012 0.006 16.70 7.4.0 0.000 0.010 14.87 7.3.33 0.000 0.005 13.44 7.3.32 0.003 0.003 13.65 7.3.31 0.000 0.008 16.64 7.3.30 0.003 0.003 16.61 7.3.29 0.007 0.013 16.59 7.3.28 0.013 0.011 16.58 7.3.27 0.020 0.006 17.40 7.3.26 0.008 0.010 16.68 7.3.25 0.010 0.009 16.71 7.3.24 0.012 0.007 16.72 7.3.23 0.012 0.006 16.60 7.3.21 0.013 0.006 16.87 7.3.20 0.009 0.009 16.66 7.3.19 0.006 0.011 16.73 7.3.18 0.006 0.015 16.50 7.3.17 0.010 0.007 16.61 7.3.16 0.008 0.008 16.55 7.2.33 0.013 0.007 16.72 7.2.32 0.008 0.015 16.96 7.2.31 0.007 0.014 17.00 7.2.30 0.009 0.009 16.90 7.2.29 0.009 0.009 16.94 7.2.6 0.003 0.010 16.92 7.1.20 0.003 0.009 16.03 7.1.11 0.020 0.007 16.51 7.1.10 0.019 0.009 16.45 7.1.9 0.027 0.007 16.48 7.1.8 0.029 0.010 16.43 7.1.7 0.016 0.013 15.45 7.1.6 0.033 0.013 33.29 7.1.5 0.048 0.007 33.28 7.1.4 0.032 0.014 32.76 7.1.3 0.037 0.009 32.82 7.1.2 0.030 0.017 32.98 7.1.1 0.021 0.011 15.08 7.1.0 0.030 0.007 15.01 7.0.25 0.018 0.009 16.36 7.0.24 0.021 0.006 16.18 7.0.23 0.022 0.007 16.15 7.0.22 0.027 0.003 16.22 7.0.21 0.107 0.006 14.96 7.0.20 0.023 0.008 15.09 7.0.19 0.022 0.010 14.89 7.0.18 0.018 0.014 14.68 7.0.17 0.029 0.011 14.66 7.0.16 0.020 0.013 14.84 7.0.15 0.024 0.007 14.52 7.0.14 0.026 0.015 14.66 7.0.13 0.026 0.013 14.78 7.0.12 0.023 0.013 14.77 7.0.11 0.028 0.013 14.73 7.0.10 0.028 0.009 14.64 7.0.9 0.033 0.012 14.57 7.0.8 0.033 0.022 14.64 7.0.7 0.031 0.013 14.60 7.0.6 0.021 0.010 14.56 7.0.5 0.022 0.007 14.87 7.0.4 0.022 0.006 14.78 7.0.3 0.019 0.010 14.73 7.0.2 0.046 0.008 14.81 7.0.1 0.035 0.007 14.71 7.0.0 0.032 0.007 14.65
preferences:dark mode live preview
77.39 ms | 400 KiB | 5 Q