|
@@ -0,0 +1,43 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+class Drink
|
|
|
+{
|
|
|
+
|
|
|
+ public $num = 5;
|
|
|
+
|
|
|
+ public $topUnit = 4;
|
|
|
+
|
|
|
+ public $bottleUnit = 2;
|
|
|
+
|
|
|
+ public $leftTop;
|
|
|
+
|
|
|
+ public $leftBottle;
|
|
|
+
|
|
|
+ public $sum = 0;
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->sum = $this->num + $this->cal($this->num, $this->num);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function cal($top, $bottle)
|
|
|
+ {
|
|
|
+ if ($top >= $this->topUnit || $bottle >= $this->bottleUnit) {
|
|
|
+ $this->leftTop = intval($top / $this->topUnit) + $top % $this->topUnit + intval($bottle / $this->bottleUnit);
|
|
|
+ $this->leftBottle = intval($bottle / $this->bottleUnit) + $bottle % $this->bottleUnit + intval($top / $this->topUnit);
|
|
|
+ $this->sum = intval($top / $this->topUnit) + intval($bottle / $this->bottleUnit) + $this->cal($this->leftTop, $this->leftBottle);
|
|
|
+
|
|
|
+ return $this->sum;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function __toString()
|
|
|
+ {
|
|
|
+ return (string) $this->sum;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+$c = new Drink();
|
|
|
+echo $c;
|