Menu
CoddyTech

回顾:配送规则

Coddy 面向 C# 开发者的 PHP 课程的第 12 课,共 48 课。

challenge icon

挑战

简单

输入为 [total, member],其中 total 是非负整数,member 是布尔值。当 total 至少为 50,或者 member 为 true 且 total 至少为 20 时,shipping 为 0;否则为 5。

提供的 main 脚本会从标准输入读取一个 JSON 值,检查指定的公开 API,并打印结果。请实现模块声明,不要打印内容;不要替换启动脚本,也不要从模块中读取输入。输入符合所述类型和范围。

编辑 Functions.php。main.php 是锁定的入口文件。依赖项通过 require_once __DIR__ 和相对文件名引入。

亲手试试

<?php
declare(strict_types=1);
require_once __DIR__."/Functions.php";
function ensure(bool $ok,string $message):void{if(!$ok)throw new RuntimeException("API: ".$message);}

$input=json_decode(trim(stream_get_contents(STDIN)),true,512,JSON_THROW_ON_ERROR);
ensure(shipping(0,true)===5 && shipping(30,false)===5,"shipping");
echo (string)shipping(...$input),"\n";

面向 C# 开发者的 PHP中的所有课

自己练习: PHP 在线编译器