@ 2017-11-12T19:37:00Z <?php
error_reporting(-1);
abstract class AbstractWorker{
public $rank;
public $isBoss;
public function __construct(int $rank, int $isBoss) {
$this->rank = $rank;
$this->isBoss = $isBoss;
}
public function getSalary(){
$salary = $this->getBasicSalary();
if ($this->rank == 2){
$salary *= 1.25;
} elseif ($this->rank == 3){
$salary *= 1.5;
}
if ($this->isBoss == 1){
$salary *= 1.5;
}
return $salary;
}
public function getCoffee(){
$coffee = $this->getBasicCoffee();
if ($this->isBoss == 1){
$coffee *= 2;
}
return $coffee;
}
public function getPages(){
$pages = $this->getBasicPages();
if ($this->isBoss == 1){
$pages *= 0;
}
return $pages;
}
abstract function getBasicSalary();
abstract function getBasicCoffee();
abstract function getBasicPages();
}
class Manager extends AbstractWorker{
public function getBasicSalary(){
return 500;
}
public function getBasicCoffee(){
return 20;
}
public function getBasicPages(){
return 200;
}
}
class Marketer extends AbstractWorker{
public function getBasicSalary(){
return 400;
}
public function getBasicCoffee(){
return 15;
}
public function getBasicPages(){
return 150;
}
}
class Engineer extends AbstractWorker{
public function getBasicSalary(){
return 200;
}
public function getBasicCoffee(){
return 5;
}
public function getBasicPages(){
return 50;
}
}
class Analyst extends AbstractWorker{
public function getBasicSalary(){
return 800;
}
public function getBasicCoffee(){
return 50;
}
public function getBasicPages(){
return 5;
}
}
class Department{
private $name;
private $workers = array();
public function __construct(string $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 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(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 Analyst ($rang, $isBoss));
}
}
}
}
class Company{
private $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);
echo "\n";
$departmentInformation = array("name" => "",
"count" => 0,
"salary" => 0,
"coffee" => 0,
"pages" => 0,
"salaryDividePages" => 0);
foreach ($company->getDepartments() as $department) {
$departmentInformation["name"] = $department->getDepartmentName();
$departmentInformation["count"] = $department->getNumberWorkers();
$departmentInformation["salary"] = $department->getDepartmentSalary();
$departmentInformation["coffee"] = $department->getDepartmentCoffee();
$departmentInformation["pages"] = $department->getDepartmentPages();
$departmentInformation["salaryDividePages"] = round($department->getDepartmentSalary() / $department->getDepartmentPages(), 1);
$this->calculatiotOfOutput($departmentInformation);
}
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();
$totalInformation["salaryDividePages"] += round($department->getDepartmentSalary() / $department->getDepartmentPages(), 1);
}
$this->calculatiotOfOutput($totalInformation);
$averageInformation = array("name" => "Среднее",
"count" => round($totalInformation["count"] / $company->getDepartmentCount(), 1),
"salary" => round($totalInformation["salary"] / $company->getDepartmentCount(), 1),
"coffee" => round($totalInformation["coffee"] / $company->getDepartmentCount(), 1),
"pages" => round($totalInformation["pages"] / $company->getDepartmentCount(), 1),
"salaryDividePages" => round($totalInformation["salaryDividePages"] / $company->getDepartmentCount()), 1);
$this->calculatiotOfOutput($averageInformation);
}
}
$vektor = new Company;
$tabel = new Tabel;
$departmentOfProcurement = new Department("Закупок");
$departmentOfProcurement->addWorkersToDepartment("Manager", 9, 1, 0);
$departmentOfProcurement->addWorkersToDepartment("Manager", 3, 2, 0);
$departmentOfProcurement->addWorkersToDepartment("Manager", 2, 3, 0);
$departmentOfProcurement->addWorkersToDepartment("Marketer", 2, 1, 0);
$departmentOfProcurement->addWorkersToDepartment("Manager", 1, 2, 1);
$departmentOfSales = new Department("Продаж");
$departmentOfSales->addWorkersToDepartment("Manager", 12, 1, 0);
$departmentOfSales->addWorkersToDepartment("Marketer", 6, 1, 0);
$departmentOfSales->addWorkersToDepartment("Analyst", 3, 1, 0);
$departmentOfSales->addWorkersToDepartment("Analyst", 2, 2, 0);
$departmentOfSales->addWorkersToDepartment("Marketer", 1, 2, 1);
$departmentOfAdvertising = new Department("Рекламы");
$departmentOfAdvertising->addWorkersToDepartment("Marketer", 15, 1, 0);
$departmentOfAdvertising->addWorkersToDepartment("Marketer", 10, 2, 0);
$departmentOfAdvertising->addWorkersToDepartment("Manager", 8, 1, 0);
$departmentOfAdvertising->addWorkersToDepartment("Engineer", 2, 1, 0);
$departmentOfAdvertising->addWorkersToDepartment("Marketer", 1, 3, 1);
$departmentOfLogistics = new Department("Логистики");
$departmentOfLogistics->addWorkersToDepartment("Manager", 13, 1, 0);
$departmentOfLogistics->addWorkersToDepartment("Manager", 5, 2, 0);
$departmentOfLogistics->addWorkersToDepartment("Engineer", 5, 1, 0);
$departmentOfLogistics->addWorkersToDepartment("Manager", 1, 1, 1);
$vektor->addDepartment($departmentOfProcurement);
$vektor->addDepartment($departmentOfSales);
$vektor->addDepartment($departmentOfAdvertising);
$vektor->addDepartment($departmentOfLogistics);
$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.007 0.011 16.88 8.3.5 0.007 0.010 18.60 8.3.4 0.004 0.011 18.84 8.3.3 0.000 0.015 18.88 8.3.2 0.005 0.003 20.41 8.3.1 0.000 0.008 23.79 8.3.0 0.000 0.008 23.69 8.2.18 0.010 0.010 25.92 8.2.17 0.012 0.006 18.95 8.2.16 0.007 0.015 22.96 8.2.15 0.000 0.008 25.66 8.2.14 0.000 0.008 24.66 8.2.13 0.004 0.004 26.16 8.2.12 0.000 0.008 19.39 8.2.11 0.003 0.007 22.29 8.2.10 0.009 0.004 18.09 8.2.9 0.000 0.008 19.43 8.2.8 0.004 0.004 18.29 8.2.7 0.004 0.008 17.75 8.2.6 0.008 0.000 18.18 8.2.5 0.004 0.004 18.10 8.2.4 0.004 0.004 20.88 8.2.3 0.000 0.008 21.08 8.2.2 0.003 0.005 18.25 8.2.1 0.003 0.005 18.39 8.2.0 0.003 0.006 18.28 8.1.28 0.009 0.006 25.92 8.1.27 0.008 0.000 22.32 8.1.26 0.000 0.009 26.35 8.1.25 0.008 0.000 28.09 8.1.24 0.006 0.003 19.20 8.1.23 0.006 0.006 19.33 8.1.22 0.004 0.004 17.91 8.1.21 0.006 0.003 18.77 8.1.20 0.003 0.009 17.60 8.1.19 0.006 0.003 17.38 8.1.18 0.005 0.003 18.10 8.1.17 0.000 0.008 18.83 8.1.16 0.000 0.008 19.29 8.1.15 0.000 0.008 18.98 8.1.14 0.004 0.004 17.89 8.1.13 0.000 0.008 19.14 8.1.12 0.008 0.000 17.72 8.1.11 0.000 0.008 17.70 8.1.10 0.000 0.008 17.61 8.1.9 0.004 0.004 17.63 8.1.8 0.000 0.008 17.73 8.1.7 0.007 0.000 17.63 8.1.6 0.000 0.009 17.92 8.1.5 0.003 0.006 17.84 8.1.4 0.004 0.004 17.80 8.1.3 0.003 0.006 17.94 8.1.2 0.004 0.004 17.84 8.1.1 0.004 0.004 17.85 8.1.0 0.005 0.003 17.71 8.0.30 0.004 0.004 20.29 8.0.29 0.000 0.008 17.00 8.0.28 0.000 0.007 18.59 8.0.27 0.004 0.004 17.59 8.0.26 0.004 0.004 20.81 8.0.25 0.004 0.004 17.35 8.0.24 0.005 0.003 17.26 8.0.23 0.000 0.007 17.27 8.0.22 0.000 0.008 17.23 8.0.21 0.004 0.004 17.16 8.0.20 0.000 0.007 17.28 8.0.19 0.000 0.009 17.27 8.0.18 0.003 0.005 17.15 8.0.17 0.008 0.000 17.25 8.0.16 0.006 0.003 17.31 8.0.15 0.008 0.004 17.20 8.0.14 0.006 0.003 17.17 8.0.13 0.003 0.003 13.64 8.0.12 0.003 0.006 17.30 8.0.11 0.003 0.005 17.24 8.0.10 0.003 0.005 17.13 8.0.9 0.003 0.005 17.13 8.0.8 0.009 0.006 17.29 8.0.7 0.006 0.003 17.29 8.0.6 0.003 0.005 17.08 8.0.5 0.004 0.004 17.26 8.0.3 0.012 0.011 17.38 8.0.2 0.011 0.010 17.50 8.0.1 0.005 0.003 17.32 8.0.0 0.014 0.006 16.87 7.4.33 0.000 0.005 16.84 7.4.32 0.004 0.004 16.74 7.4.30 0.003 0.003 16.83 7.4.29 0.004 0.004 16.82 7.4.28 0.000 0.009 16.81 7.4.27 0.004 0.004 16.72 7.4.26 0.000 0.008 16.70 7.4.25 0.003 0.005 16.80 7.4.24 0.008 0.000 16.87 7.4.23 0.003 0.006 16.63 7.4.22 0.011 0.007 16.76 7.4.21 0.011 0.005 16.76 7.4.20 0.004 0.004 16.63 7.4.16 0.009 0.009 16.71 7.4.15 0.010 0.010 17.40 7.4.14 0.007 0.013 17.86 7.4.13 0.013 0.009 16.67 7.4.12 0.011 0.010 16.70 7.4.11 0.013 0.006 16.74 7.4.10 0.013 0.013 16.65 7.4.9 0.015 0.003 16.67 7.4.8 0.012 0.009 19.39 7.4.7 0.014 0.011 16.73 7.4.6 0.003 0.017 16.83 7.4.5 0.010 0.007 16.80 7.4.4 0.011 0.007 16.70 7.4.3 0.006 0.013 16.72 7.4.0 0.008 0.011 15.06 7.3.33 0.005 0.000 13.54 7.3.32 0.003 0.003 13.40 7.3.31 0.008 0.000 16.48 7.3.30 0.002 0.005 16.52 7.3.29 0.003 0.005 16.63 7.3.28 0.008 0.011 16.60 7.3.27 0.013 0.006 17.40 7.3.26 0.006 0.018 16.74 7.3.25 0.008 0.012 16.58 7.3.24 0.011 0.007 16.68 7.3.23 0.014 0.009 16.54 7.3.21 0.012 0.009 16.82 7.3.20 0.009 0.009 16.81 7.3.19 0.005 0.013 16.89 7.3.18 0.003 0.014 16.54 7.3.17 0.012 0.006 16.55 7.3.16 0.004 0.014 16.81 7.3.12 0.006 0.012 15.13 7.3.11 0.009 0.010 14.94 7.3.10 0.006 0.008 14.97 7.3.9 0.007 0.008 14.99 7.3.8 0.007 0.008 14.82 7.3.7 0.003 0.011 14.97 7.3.6 0.009 0.004 15.02 7.3.5 0.005 0.008 15.01 7.3.4 0.006 0.008 14.76 7.3.3 0.007 0.008 14.90 7.3.2 0.007 0.008 16.60 7.3.1 0.009 0.006 16.70 7.3.0 0.003 0.010 16.71 7.2.33 0.009 0.009 16.88 7.2.32 0.011 0.009 16.89 7.2.31 0.003 0.020 17.04 7.2.30 0.008 0.010 16.72 7.2.29 0.016 0.010 17.08 7.2.25 0.005 0.011 15.14 7.2.24 0.006 0.012 15.23 7.2.23 0.011 0.004 15.30 7.2.22 0.003 0.009 15.41 7.2.21 0.002 0.010 15.15 7.2.20 0.007 0.007 15.18 7.2.19 0.003 0.011 15.13 7.2.18 0.007 0.007 15.23 7.2.17 0.007 0.006 15.14 7.2.6 0.006 0.009 16.73 7.1.33 0.006 0.008 15.83 7.1.32 0.004 0.010 15.79 7.1.31 0.005 0.008 15.87 7.1.30 0.004 0.010 15.85 7.1.29 0.003 0.009 15.79 7.1.28 0.006 0.008 15.87 7.1.27 0.005 0.009 15.83 7.1.26 0.006 0.009 15.67 7.1.20 0.014 0.003 15.51 7.1.11 0.026 0.016 16.29 7.1.10 0.029 0.013 16.29 7.1.9 0.024 0.010 16.57 7.1.8 0.029 0.013 16.16 7.1.7 0.036 0.013 15.52 7.1.6 0.035 0.007 33.25 7.1.5 0.033 0.010 33.14 7.1.4 0.036 0.009 32.82 7.1.3 0.045 0.006 32.76 7.1.2 0.040 0.013 32.98 7.1.1 0.023 0.015 14.96 7.1.0 0.034 0.006 15.00 7.0.25 0.031 0.009 16.14 7.0.24 0.030 0.013 15.96 7.0.23 0.020 0.013 15.91 7.0.22 0.029 0.013 15.93 7.0.21 0.035 0.014 14.73 7.0.20 0.020 0.013 15.05 7.0.19 0.017 0.010 15.00 7.0.18 0.016 0.013 14.80 7.0.17 0.038 0.014 14.57 7.0.16 0.024 0.012 14.56 7.0.15 0.042 0.014 14.48 7.0.14 0.029 0.009 14.62 7.0.13 0.035 0.010 14.78 7.0.12 0.034 0.009 14.69 7.0.11 0.126 0.010 14.77 7.0.10 0.037 0.009 14.47 7.0.9 0.039 0.009 14.58 7.0.8 0.025 0.006 14.92 7.0.7 0.037 0.007 14.87 7.0.6 0.027 0.004 14.43 7.0.5 0.036 0.009 14.97 7.0.4 0.020 0.010 14.77 7.0.3 0.029 0.016 14.80 7.0.2 0.023 0.007 14.84 7.0.1 0.023 0.010 14.70 7.0.0 0.034 0.006 14.82
preferences:dark mode live preview
39.3 ms | 400 KiB | 5 Q