@ 2017-11-12T14:25:39Z <?php
error_reporting(-1);
abstract class AbstractWorker{
private $rank;
private $isBoss;
private $coffee;
private $salary;
public $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;
// }
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.014 0.007 18.43 8.3.5 0.011 0.004 18.03 8.3.4 0.006 0.009 18.98 8.3.3 0.009 0.006 18.79 8.3.2 0.004 0.004 20.43 8.3.1 0.005 0.003 23.61 8.3.0 0.005 0.003 23.65 8.2.18 0.012 0.003 16.38 8.2.17 0.000 0.018 22.96 8.2.16 0.011 0.004 19.39 8.2.15 0.005 0.003 24.18 8.2.14 0.004 0.004 24.66 8.2.13 0.008 0.000 22.25 8.2.12 0.004 0.004 26.35 8.2.11 0.010 0.013 22.30 8.2.10 0.011 0.000 19.19 8.2.9 0.006 0.003 19.17 8.2.8 0.009 0.000 18.05 8.2.7 0.006 0.006 17.36 8.2.6 0.008 0.000 18.04 8.2.5 0.000 0.008 18.10 8.2.4 0.000 0.010 20.52 8.2.3 0.003 0.006 20.95 8.2.2 0.008 0.000 18.07 8.2.1 0.004 0.004 18.12 8.2.0 0.004 0.004 18.12 8.1.28 0.009 0.006 25.92 8.1.27 0.008 0.000 23.99 8.1.26 0.004 0.004 26.35 8.1.25 0.010 0.000 28.09 8.1.24 0.005 0.005 22.51 8.1.23 0.000 0.012 19.33 8.1.22 0.004 0.004 17.91 8.1.21 0.005 0.003 18.77 8.1.20 0.003 0.007 17.60 8.1.19 0.004 0.004 17.47 8.1.18 0.008 0.000 18.10 8.1.17 0.004 0.004 19.09 8.1.16 0.004 0.004 19.04 8.1.15 0.004 0.004 20.72 8.1.14 0.004 0.004 17.86 8.1.13 0.000 0.007 18.93 8.1.12 0.000 0.007 17.64 8.1.11 0.003 0.005 17.49 8.1.10 0.004 0.004 17.50 8.1.9 0.000 0.007 17.41 8.1.8 0.004 0.004 17.49 8.1.7 0.002 0.005 17.42 8.1.6 0.004 0.004 17.71 8.1.5 0.004 0.004 17.64 8.1.4 0.004 0.004 17.51 8.1.3 0.000 0.008 17.77 8.1.2 0.002 0.010 17.77 8.1.1 0.008 0.000 17.64 8.1.0 0.000 0.008 17.59 8.0.30 0.010 0.000 19.82 8.0.29 0.005 0.003 16.63 8.0.28 0.005 0.002 18.62 8.0.27 0.000 0.007 17.39 8.0.26 0.000 0.007 20.64 8.0.25 0.004 0.004 17.13 8.0.24 0.007 0.000 17.04 8.0.23 0.000 0.007 17.18 8.0.22 0.005 0.003 17.00 8.0.21 0.003 0.003 16.97 8.0.20 0.000 0.007 17.19 8.0.19 0.000 0.009 17.23 8.0.18 0.005 0.003 16.95 8.0.17 0.005 0.003 17.10 8.0.16 0.004 0.004 16.96 8.0.15 0.000 0.007 17.08 8.0.14 0.004 0.004 17.04 8.0.13 0.003 0.003 13.56 8.0.12 0.000 0.008 17.00 8.0.11 0.000 0.008 17.05 8.0.10 0.002 0.005 16.98 8.0.9 0.004 0.004 17.13 8.0.8 0.013 0.003 17.10 8.0.7 0.004 0.004 17.06 8.0.6 0.002 0.005 17.07 8.0.5 0.004 0.004 16.97 8.0.3 0.009 0.011 17.17 8.0.2 0.010 0.010 17.40 8.0.1 0.004 0.004 17.19 8.0.0 0.006 0.013 16.80 7.4.33 0.005 0.000 16.84 7.4.32 0.000 0.006 16.61 7.4.30 0.007 0.000 16.64 7.4.29 0.003 0.003 16.53 7.4.28 0.008 0.000 16.48 7.4.27 0.005 0.002 16.48 7.4.26 0.004 0.004 16.60 7.4.25 0.004 0.004 16.64 7.4.24 0.004 0.004 16.60 7.4.23 0.008 0.000 16.79 7.4.22 0.006 0.013 16.61 7.4.21 0.009 0.015 16.71 7.4.20 0.004 0.004 16.48 7.4.16 0.016 0.006 16.55 7.4.15 0.011 0.008 17.40 7.4.14 0.011 0.009 17.86 7.4.13 0.012 0.012 16.82 7.4.12 0.010 0.011 16.65 7.4.11 0.008 0.008 16.70 7.4.10 0.010 0.014 16.47 7.4.9 0.009 0.009 16.67 7.4.8 0.018 0.000 19.39 7.4.7 0.013 0.009 16.57 7.4.6 0.012 0.008 16.68 7.4.5 0.003 0.009 16.51 7.4.4 0.011 0.006 16.50 7.4.3 0.007 0.010 16.48 7.4.0 0.000 0.016 15.05 7.3.33 0.000 0.005 13.45 7.3.32 0.003 0.003 13.54 7.3.31 0.000 0.007 16.46 7.3.30 0.000 0.008 16.53 7.3.29 0.008 0.008 16.57 7.3.28 0.010 0.008 16.58 7.3.27 0.012 0.015 17.40 7.3.26 0.010 0.009 16.83 7.3.25 0.009 0.011 16.70 7.3.24 0.006 0.014 16.56 7.3.23 0.008 0.011 16.82 7.3.21 0.006 0.012 16.73 7.3.20 0.013 0.006 16.87 7.3.19 0.011 0.008 16.68 7.3.18 0.004 0.013 16.60 7.3.17 0.013 0.004 16.68 7.3.16 0.008 0.008 16.64 7.3.1 0.005 0.005 16.83 7.3.0 0.003 0.008 16.77 7.2.33 0.013 0.006 16.98 7.2.32 0.004 0.020 17.00 7.2.31 0.018 0.006 16.65 7.2.30 0.015 0.004 16.84 7.2.29 0.010 0.007 17.04 7.2.13 0.000 0.016 17.02 7.2.12 0.003 0.012 17.11 7.2.11 0.007 0.004 17.06 7.2.10 0.008 0.008 17.13 7.2.9 0.012 0.004 16.79 7.2.8 0.003 0.009 17.11 7.2.7 0.003 0.006 16.94 7.2.6 0.003 0.008 16.95 7.2.5 0.007 0.003 16.73 7.2.4 0.006 0.008 17.09 7.2.3 0.004 0.011 17.30 7.2.2 0.003 0.006 17.12 7.2.1 0.003 0.012 17.12 7.2.0 0.010 0.007 16.97 7.1.25 0.009 0.006 16.11 7.1.20 0.007 0.000 15.91 7.1.11 0.020 0.014 16.52 7.1.10 0.046 0.007 16.62 7.1.9 0.029 0.006 16.66 7.1.8 0.022 0.010 16.32 7.1.7 0.039 0.006 15.65 7.1.6 0.063 0.016 33.21 7.1.5 0.064 0.016 33.30 7.1.4 0.038 0.017 33.00 7.1.3 0.127 0.016 32.96 7.1.2 0.029 0.022 32.85 7.1.1 0.022 0.013 15.04 7.1.0 0.028 0.006 14.99 7.0.25 0.037 0.007 16.12 7.0.24 0.033 0.011 16.29 7.0.23 0.023 0.010 16.26 7.0.22 0.019 0.012 16.06 7.0.21 0.039 0.010 14.93 7.0.20 0.031 0.014 14.92 7.0.19 0.040 0.011 14.89 7.0.18 0.070 0.007 14.81 7.0.17 0.028 0.010 14.87 7.0.16 0.025 0.013 14.59 7.0.15 0.025 0.007 14.84 7.0.14 0.037 0.017 14.62 7.0.13 0.034 0.012 14.88 7.0.12 0.033 0.013 14.77 7.0.11 0.025 0.011 14.76 7.0.10 0.023 0.013 14.45 7.0.9 0.031 0.009 14.60 7.0.8 0.034 0.013 14.67 7.0.7 0.030 0.008 14.45 7.0.6 0.037 0.014 14.64 7.0.5 0.028 0.006 14.88 7.0.4 0.028 0.006 14.78 7.0.3 0.029 0.006 15.00 7.0.2 0.028 0.007 14.81 7.0.1 0.028 0.010 14.53 7.0.0 0.040 0.008 14.82
preferences:dark mode live preview
54.41 ms | 400 KiB | 5 Q