@ 2017-11-12T14:30:16Z <?php
error_reporting(-1);
abstract class AbstractWorker{
public $rank;
public $isBoss;
public $coffee;
public $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() / $department->getDepartmentPages(), 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 16.63 8.3.5 0.012 0.003 18.35 8.3.4 0.004 0.018 18.78 8.3.3 0.011 0.004 18.97 8.3.2 0.008 0.000 20.34 8.3.1 0.007 0.000 23.73 8.3.0 0.004 0.004 23.69 8.2.18 0.003 0.012 16.50 8.2.17 0.010 0.010 22.96 8.2.16 0.013 0.003 20.27 8.2.15 0.000 0.008 24.18 8.2.14 0.004 0.004 24.66 8.2.13 0.008 0.000 26.16 8.2.12 0.003 0.005 19.89 8.2.11 0.008 0.003 22.34 8.2.10 0.008 0.004 17.97 8.2.9 0.004 0.004 19.20 8.2.8 0.003 0.006 18.16 8.2.7 0.004 0.007 17.75 8.2.6 0.003 0.005 18.05 8.2.5 0.003 0.006 18.10 8.2.4 0.004 0.004 20.65 8.2.3 0.003 0.005 21.14 8.2.2 0.008 0.000 18.14 8.2.1 0.008 0.000 18.36 8.2.0 0.004 0.004 18.16 8.1.28 0.012 0.006 25.92 8.1.27 0.008 0.000 23.91 8.1.26 0.008 0.000 26.35 8.1.25 0.004 0.004 28.09 8.1.24 0.006 0.003 23.77 8.1.23 0.007 0.004 21.13 8.1.22 0.000 0.008 17.74 8.1.21 0.006 0.003 18.77 8.1.20 0.003 0.006 17.48 8.1.19 0.006 0.003 17.48 8.1.18 0.004 0.004 18.10 8.1.17 0.006 0.003 19.27 8.1.16 0.004 0.004 19.20 8.1.15 0.004 0.004 20.73 8.1.14 0.004 0.004 17.77 8.1.13 0.004 0.004 19.02 8.1.12 0.004 0.004 17.64 8.1.11 0.000 0.008 17.59 8.1.10 0.000 0.008 17.58 8.1.9 0.004 0.004 17.61 8.1.8 0.008 0.000 17.50 8.1.7 0.000 0.007 17.61 8.1.6 0.008 0.000 17.75 8.1.5 0.009 0.000 17.71 8.1.4 0.004 0.004 17.76 8.1.3 0.003 0.006 17.74 8.1.2 0.006 0.006 17.84 8.1.1 0.003 0.005 17.79 8.1.0 0.000 0.008 17.68 8.0.30 0.000 0.008 18.77 8.0.29 0.000 0.008 17.13 8.0.28 0.000 0.007 18.52 8.0.27 0.005 0.003 17.52 8.0.26 0.007 0.000 20.70 8.0.25 0.000 0.007 17.18 8.0.24 0.003 0.003 17.24 8.0.23 0.003 0.006 17.12 8.0.22 0.005 0.003 17.16 8.0.21 0.008 0.000 17.19 8.0.20 0.004 0.004 17.10 8.0.19 0.004 0.004 17.23 8.0.18 0.004 0.004 17.19 8.0.17 0.000 0.007 17.18 8.0.16 0.000 0.007 17.15 8.0.15 0.008 0.000 17.12 8.0.14 0.000 0.007 17.17 8.0.13 0.006 0.000 13.54 8.0.12 0.008 0.000 16.95 8.0.11 0.000 0.007 17.17 8.0.10 0.004 0.004 16.95 8.0.9 0.004 0.004 17.01 8.0.8 0.010 0.013 17.16 8.0.7 0.004 0.004 17.02 8.0.6 0.000 0.008 17.14 8.0.5 0.004 0.004 17.17 8.0.3 0.011 0.010 17.19 8.0.2 0.011 0.009 17.42 8.0.1 0.003 0.005 17.01 8.0.0 0.007 0.011 17.18 7.4.33 0.000 0.006 16.88 7.4.32 0.000 0.007 16.81 7.4.30 0.006 0.000 16.55 7.4.29 0.004 0.004 16.66 7.4.28 0.004 0.004 16.63 7.4.27 0.004 0.004 16.71 7.4.26 0.003 0.006 16.75 7.4.25 0.006 0.003 16.62 7.4.24 0.000 0.007 16.73 7.4.23 0.000 0.008 16.73 7.4.22 0.016 0.006 16.69 7.4.21 0.011 0.011 16.61 7.4.20 0.005 0.002 16.77 7.4.16 0.007 0.011 16.68 7.4.15 0.021 0.021 17.40 7.4.14 0.010 0.010 17.86 7.4.13 0.004 0.014 16.64 7.4.12 0.008 0.010 16.68 7.4.11 0.007 0.022 16.81 7.4.10 0.013 0.010 16.75 7.4.9 0.004 0.014 16.68 7.4.8 0.003 0.017 19.39 7.4.7 0.010 0.014 16.55 7.4.6 0.008 0.009 16.75 7.4.5 0.010 0.007 16.40 7.4.4 0.004 0.014 16.73 7.4.3 0.000 0.018 16.89 7.4.0 0.008 0.006 14.95 7.3.33 0.000 0.005 13.54 7.3.32 0.003 0.003 13.54 7.3.31 0.000 0.007 16.34 7.3.30 0.005 0.003 16.52 7.3.29 0.013 0.005 16.49 7.3.28 0.007 0.011 16.51 7.3.27 0.007 0.014 17.40 7.3.26 0.010 0.008 16.69 7.3.25 0.008 0.012 16.57 7.3.24 0.010 0.009 16.51 7.3.23 0.017 0.006 16.77 7.3.21 0.007 0.010 16.71 7.3.20 0.013 0.006 16.54 7.3.19 0.013 0.006 16.54 7.3.18 0.017 0.003 16.50 7.3.17 0.011 0.005 16.82 7.3.16 0.015 0.009 16.48 7.3.1 0.016 0.004 16.73 7.3.0 0.000 0.017 16.29 7.2.33 0.010 0.010 17.00 7.2.32 0.013 0.014 17.02 7.2.31 0.017 0.003 16.67 7.2.30 0.006 0.013 16.86 7.2.29 0.004 0.014 16.95 7.2.13 0.009 0.009 17.11 7.2.12 0.000 0.018 16.91 7.2.11 0.014 0.007 16.94 7.2.10 0.019 0.000 17.01 7.2.9 0.014 0.007 17.01 7.2.8 0.010 0.007 16.99 7.2.7 0.007 0.010 17.05 7.2.6 0.004 0.010 16.80 7.2.5 0.003 0.010 17.06 7.2.4 0.004 0.012 17.13 7.2.3 0.007 0.011 17.16 7.2.2 0.003 0.013 16.91 7.2.1 0.004 0.014 17.00 7.2.0 0.007 0.004 17.09 7.1.25 0.005 0.005 15.83 7.1.20 0.007 0.004 15.59 7.1.11 0.066 0.013 15.97 7.1.10 0.052 0.010 16.17 7.1.9 0.156 0.012 16.29 7.1.8 0.038 0.016 16.46 7.1.7 0.056 0.014 15.54 7.1.6 0.051 0.019 33.36 7.1.5 0.067 0.016 33.31 7.1.4 0.075 0.016 32.77 7.1.3 0.106 0.012 32.86 7.1.2 0.083 0.013 32.68 7.1.1 0.043 0.015 14.81 7.1.0 0.057 0.015 15.23 7.0.25 0.041 0.019 15.67 7.0.24 0.044 0.007 15.93 7.0.23 0.061 0.013 16.23 7.0.22 0.063 0.012 15.88 7.0.21 0.040 0.011 14.84 7.0.20 0.072 0.010 15.15 7.0.19 0.051 0.016 15.16 7.0.18 0.067 0.010 14.65 7.0.17 0.079 0.003 14.58 7.0.16 0.070 0.019 14.66 7.0.15 0.040 0.007 14.43 7.0.14 0.048 0.006 14.55 7.0.13 0.059 0.017 14.71 7.0.12 0.059 0.017 14.87 7.0.11 0.062 0.022 14.59 7.0.10 0.062 0.010 14.83 7.0.9 0.060 0.013 14.50 7.0.8 0.121 0.013 14.81 7.0.7 0.036 0.011 14.69 7.0.6 0.079 0.016 14.47 7.0.5 0.059 0.016 14.61 7.0.4 0.057 0.010 14.70 7.0.3 0.040 0.011 14.89 7.0.2 0.047 0.016 14.61 7.0.1 0.063 0.009 14.66 7.0.0 0.066 0.007 14.55
preferences:dark mode live preview
50.56 ms | 401 KiB | 5 Q