回顾:整数分
Coddy 面向 JavaScript 开发者的 PHP 课程的第 24 课,共 48 课。
挑战
简单输入为 [prices,discount],prices 是非负整数分值,discount 的范围为 0..100。discounted 返回 floor(total*(100-discount)/100)。总额最多为 100000。
提供的主脚本会从标准输入读取一个 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(discounted([15],10)===13,"integer floor");
echo (string)discounted(...$input),"\n";
面向 JavaScript 开发者的 PHP中的所有课
自己练习: PHP 在线编译器