如何解决我需要弄清楚要覆盖一个区域需要多少涂料,但是我遇到了问题帮帮我或给我个主意
$width = 10; //width
$length = 10; //Length
$door = 2; // Door area
$square = $width * $length - $door; //Total area to be painted
$perMeter = 1; //Where $w is the amount of paint to paint 1m2
$total = $square * $perMeter; //The total amount of paint is sufficient for painting.
$containers = array(5,12,18,4,8,1); //The values for the number of containers are in liters.
需要多少桶5,1(将逐渐从最大的部分变成最小的部分)
解决方法
整个文件看起来像这样
<?php
declare(strict_types=1);
$width = 10; //width
$length = 10; //Length
$door = 2; // Door area
$square = $width * $length - $door; //Total area to be painted
$perMeter = 1; //Where $w is the amount of paint to paint 1m2
$total = $square * $perMeter; //The total amount of paint is sufficient for painting.
echo 'Total barrels needed: ' . $total . "barrels\n";
$containers = array(5,12,18,4,8,1); //The values for the number of containers are in liters.
rsort($containers);
$counter = 0;
while ($counter < count($containers)) {
$total -= ($amount = intdiv($total,$containers[$counter])) * $containers[$counter];
echo sprintf("%d barrel container - %d\n",$containers[$counter],$amount);
$counter++;
}
看看变量名,有意义的变量名非常重要,如果您希望轻松地支持代码。当然,您可以更改变量的值。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。